У меня есть этот запрос
select count(*) as COUNT_A, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NOT NULL
group by datepart(yyyy, [Tgl_Perolehan])
и это
select count(*) as COUNT_B, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NULL
group by datepart(yyyy, [Tgl_Perolehan])
Разница составляет всего IS NOT NULL
и IS NULL
, а результат равен
+---------+--------+
| COUNT_A | year |
+----------+--------+
| 12 | 1991 |
| 15 | 1993 |
| 24 | 1998 |
+----------+--------+
Я хочу сделать вот так
+---------+---------+--------+
| COUNT_A | COUNT_B | year |
+----------+---------+--------+
| 12 | 23 | 1991 |
| 15 | 33 | 1993 |
| 24 | 13 | 1998 |
+----------+---------+--------+
и попробую вот так
select (select count(*) as COUNT_A, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NOT NULL
group by datepart(yyyy, [Tgl_Perolehan])),
(select count(*) as COUNT_B, datepart(yyyy, [Tgl_Perolehan]) as [year]
from [table_name]
where Sertifikat_Nomor IS NULL
group by datepart(yyyy, [Tgl_Perolehan]))
Но не решил мою проблему.Я использовал CASE WHEN
, но все еще не решил проблему.Как объединить и исправить их?Спасибо.