My table has 4 columns in it.
status: (This is a string that is either pended, accepted, or rejected value of P, A, or R)
source: (this is a code like BBQ5)
id: (this is a unique identifier number)
So a row would be something like
Accepted GBBG 2109202
I want to order them by how many got accepted/ rejected / pended per source
I came up with this.
SELECT status , count(status)
FROM myTable
WHERE source in (
'BB5',
'GGG',
'FEV'
)
GROUP BY status
this gives me the number of rejected count but I need it specified per code is this possible in sql ?
CodePudding user response:
use a case when for the Status categories
SELECT
source,
sum(case when status='accepted' then 1 end) accepted_count,
sum(case when status='rejected' then 1 end) rejected_count
FROM myTable
WHERE source in (
'BB5',
'GGG',
'FEV'
)
group by source