gpt4 book ai didi

MYSQL - 基本查询 where + group by +having

转载 作者:行者123 更新时间:2023-11-29 14:09:04 26 4
gpt4 key购买 nike

SELECT dieet.snr, soort.nsnaam   FROM soort
JOIN dieet ON soort.snr = dieet.snr
JOIN voedsel ON dieet.voednr = voedsel.voednr
WHERE voedsel.voednr = 22
GROUP BY dieet.snr
HAVING COUNT(*) = 1 ;

where 条件弄乱了我的输出,我做错了什么

最佳答案

我怀疑您正在寻找只有一条记录“voednr = 22”的“snr”。您的查询正在获取恰好具有这样一个“voednr”的所有“snr”以及其他“voednr”。

让我建议以下查询:

SELECT dieet.snr, soort.nsnaam
FROM soort
JOIN dieet ON soort.snr = dieet.snr
JOIN voedsel ON dieet.voednr = voedsel.voednr
GROUP BY dieet.snr
HAVING COUNT(*) = 1 and max(voedsel.voednr) = 22

这将为您提供只有 22 个的行。

关于MYSQL - 基本查询 where + group by +having,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13809764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com