【问题标题】:ERROR 1111 (HY000): Invalid use of group function MYSQL [duplicate]错误1111(HY000):组函数MYSQL的使用无效[重复]
【发布时间】:2021-11-08 09:25:47
【问题描述】:

我要显示结果

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;

我想显示结果,但是错误。 ERROR 1111 (HY000): 组函数使用无效

【问题讨论】:

    标签: mysql sql


    【解决方案1】:

    你应该使用HAVING这样的声明:

        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;
    

    WHERE 语句也可以更有效,例如:

     WHERE month(TglLahir) > 5
    

    【讨论】:

    • 空集,10 个警告(0.001 秒)
    • SELECT GolDarah, count(GolDarah) JmlPasien -> FROM tblPasien -> WHERE monthname(TglLahir) > 5 -> GROUP BY GolDarah -> HAVING count(GolDarah) = 2 -> ORDER BY GolDarah;空集,10 个警告(0.001 秒)
    猜你喜欢
    • 2018-05-14
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2021-11-03
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多