Skip to content
Advertisement

Count rows according to 2 column with Group By

I have a database table of 3 columns

I want an sql query to output the sum of rows of Deleted column grouped by CardHolderID.

However query below outputs 2 columns for CardHolderID

I want to include 2 columns as Deleted0 (count of rows with Deleted column equal to 0) and Deleted1 (count of rows with Deleted column equal to 1)

How should be the SQL query for such a result?

Kind regards

Advertisement

Answer

Using conditional count:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement