拥有超过 2 本书
HAVING more than 2 books
我必须只打印出出版超过 2 本书的出版商,但对于我的结果,我总是得到
PUB_NAME |TOTAL
--------------------------------
Abatis Publishers |4
Core Dump Books |1 <------don't want to print
Schadenfreude Press |3
Tenterhooks Press |5
ERROR 42X01: Syntax error: Encountered "HAVING"
到目前为止,这是我的代码。
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;
只需使用 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;
总计无法在 HAVING 中识别。尝试 HAVING COUNT(title_name) > 2;
同时删除“;”在 GROUP BY pub_name;
中
我必须只打印出出版超过 2 本书的出版商,但对于我的结果,我总是得到
PUB_NAME |TOTAL
--------------------------------
Abatis Publishers |4
Core Dump Books |1 <------don't want to print
Schadenfreude Press |3
Tenterhooks Press |5
ERROR 42X01: Syntax error: Encountered "HAVING"
到目前为止,这是我的代码。
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;
只需使用 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;
总计无法在 HAVING 中识别。尝试 HAVING COUNT(title_name) > 2;
同时删除“;”在 GROUP BY pub_name;
中