我必须只打印发布超过2本书的出版商,但对于我的成绩,我总是得到
PUB_NAME |TOTAL
--------------------------------
Abatis Publishers |4
Core Dump Books |1 <------don't want to print
Schadenfreude Press |3
Tenterhooks Press |5
ERROR 42X01:语法错误:遇到&#34; HAVING&#34;
到目前为止,这是我的代码。
SELECT pub_name, COUNT(title_name) AS total
FROM publishers
INNER JOIN titles
ON titles.pub_id = publishers.pub_id
GROUP BY pub_name;
HAVING total > 2;
答案 0 :(得分:2)
在HAVING中无法识别总数。尝试HAVING COUNT(title_name)&gt; 2;
同时删除';'在GROUP BY pub_name;
答案 1 :(得分:0)
只需使用WHERE
SELECT p.pub_name, COUNT(t.title_name) AS total
FROM publishers p
INNER JOIN titles t ON t.pub_id = p.pub_id
WHERE COUNT(t.title_name) > 2
GROUP BY p.pub_name;