gpt4 book ai didi

sql - 选择另一个表的计数为零的位置

转载 作者:行者123 更新时间:2023-12-02 10:53:25 25 4
gpt4 key购买 nike

我有两个表(questionsanswers),并且希望仅当 中相应的计数时才从 questions 中选择行换句话说,当没有与 questionid 匹配的答案时,>answers 为零。

到目前为止我的查询是:

SELECT q.* , COUNT(a.id) FROM questions q LEFT OUTER JOIN answers a ON q.id = a.questionid WHERE COUNT(a.id)=0

我不确定是否可以这样做,但它不起作用。有什么想法吗?

谢谢

最佳答案

尝试,

SELECT q.*
FROM questions q LEFT OUTER JOIN answers a
ON q.id = a.questionid
WHERE a.questionid IS NULL

关于sql - 选择另一个表的计数为零的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13456149/

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