我正试图获得2008年第一次生产的国家名单。
这是我的sql请求:

SELECT DISTINCT *
FROM pays p
WHERE p.id_pays != (
    SELECT DISTINCT pays.id_pays
    FROM pays
    JOIN emission ON emission.id_pays = pays.id_pays
    WHERE MIN(YEAR(emission.dateFrappe_emission)) != 2008
)

它还给了我:
“#1111-无效使用组函数”;
但这是可行的:
SELECT DISTINCT *
FROM pays p
WHERE p.id_pays != (
    SELECT DISTINCT pays.id_pays
    FROM pays
    JOIN emission ON emission.id_pays = pays.id_pays
    WHERE YEAR(emission.dateFrappe_emission) = 2008
)

你能帮帮我吗?

最佳答案

可以将聚合函数与SELECTHAVING子句一起使用,例如:

SELECT DISTINCT *
FROM pays p
WHERE p.id_pays NOT IN (SELECT pays.id_pays
                        FROM pays
                        JOIN emission
                          ON emission.id_pays = pays.id_pays
                        GROUP BY pays.id_pays
                        HAVING MIN(YEAR(emission.dateFrappe_emission)) != 2008 )

10-02 12:49