Here's the table I start with
CMS | defect_status
________________________
1 | true
2 | false
3 | true
3 | false
and here's what I want
CMS | true_defects | false_defects
1 | 1 | 0
2 | 0 | 1
3 | 1 | 1
So here's my code
SELECT DISTINCT
false_table.CMS,
true_table.true_defects,
false_table.false_defects
FROM(
SELECT DISTINCT
CMS,
COUNT(*) AS true_defects
FROM data_table
WHERE defect_status = 'true'
GROUP BY CMS
) as true_table
FULL JOIN(
SELECT DISTINCT
CMS,
COUNT(*) AS false_defects
FROM data_table
WHERE defect_status = 'false'
GROUP BY CMS
) as false_table
ON true_table.CMS = false_table.CMS
I would like to select all CMS, those in "false_table" and "true_table". If I select "false_table.CMS" (as in the code above), here's what I get :
CMS | true_defects | false_defects
2 | 0 | 1
3 | 1 | 1
CMS "1" has disappeared simply because it's not in the column false_table.CMS
Thank you