Postingan lainnya
pertanyaan soal query gan
Saya ingin menampilkan siapa saja yang Alpa > 3 dan izin = 1
ini tabelnya gan
id siswa_id keterangan created_at updated_at ------ -------- ---------- ------------------- --------------------- 4 3 Alpa 2017-08-13 09:48:08 (NULL) 5 3 Alpa 2017-08-14 09:48:22 (NULL) 37 11 Alpa 2017-08-16 15:27:16 (NULL) 39 10 Alpa 2017-08-17 10:49:04 2017-08-17 10:49:04 42 3 Alpa 2017-08-03 18:01:26 (NULL) 43 3 Alpa 2017-08-17 11:01:49 2017-08-17 11:01:49 44 13 Sakit 2017-08-18 02:57:14 2017-08-18 02:57:14 45 15 Izin 2017-08-01 13:48:40 (NULL)
0
1 Jawaban:
Kurang tau bener apa ga, tapi patut dicoba
select siswaid,count(*) as counter, keterangan from (
SELECT siswaid,count(siswaid) as count, keterangan
FROM mytable WHERE keterangan='Alpa' GROUP BY siswaid
HAVING (count > 3)
) tbl1 UNION ALL
select siswaid,count(*) as counter, keterangan from (
SELECT siswaid,count(siswaid) as count, keterangan
FROM mytable WHERE keterangan='Izin' GROUP BY siswaid
HAVING (count = 1)
) tbl2
0