-1

I want show the result

SELECT GolDarah, count(GolDarah) JmlPasien
FROM tblPasien
WHERE monthname(TglLahir) IN ('July','August','September','October','November','December') AND count(GolDarah) JmlPasien = 2
GROUP BY GolDarah
ORDER BY GolDarah;

I Want show the result, but error. ERROR 1111 (HY000): Invalid use of group function

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
Triminor
  • 13
  • 5

1 Answers1

0

You should to use HAVING statement like:

    SELECT GolDarah, count(GolDarah) JmlPasien
    FROM tblPasien
    WHERE monthname(TglLahir) IN ('July','August','September','October','November','December') 
    GROUP BY GolDarah
    HAVING count(GolDarah) = 2
    ORDER BY GolDarah;

also WHERE statement can be more effective like:

 WHERE month(TglLahir) > 5
Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
  • Empty set, 10 warnings (0.001 sec) – Triminor Nov 08 '21 at 09:36
  • SELECT GolDarah, count(GolDarah) JmlPasien -> FROM tblPasien -> WHERE monthname(TglLahir) > 5 -> GROUP BY GolDarah -> HAVING count(GolDarah) = 2 -> ORDER BY GolDarah; Empty set, 10 warnings (0.001 sec) – Triminor Nov 08 '21 at 09:40