MySQL SQL 计数 - 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7840253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:24:37  来源:igfitidea点击:

SQL count - not working

mysqlsqlcount

提问by user947462

I am trying this code:

我正在尝试这个代码:

SELECT COUNT (oferta_id_oferta) 
FROM `oferta_has_tags` 
WHERE oferta_id_oferta = 
(SELECT id_oferta FROM oferta 
WHERE oferta = "designer")

I receive error: 1630 - FUNCTION mydb.COUNT does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual

我收到 error: 1630 - FUNCTION mydb.COUNT does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual

If I remove the COUNTword, I get two results.

如果我删除这个COUNT词,我会得到两个结果。

What is the problem?

问题是什么?

回答by msarchet

Don't put a space

不要放空格

SELECT COUNT(oferta_id_oferta) 
FROM `oferta_has_tags` 
WHERE oferta_id_oferta = 
(SELECT id_oferta FROM oferta 
WHERE oferta = "designer")

回答by ObscureRobot

Try removing the space between COUNT and the parentheses:

尝试删除 COUNT 和括号之间的空格:

SELECT COUNT(oferta_id_oferta) 
FROM `oferta_has_tags` 
WHERE oferta_id_oferta = 
(SELECT id_oferta FROM oferta 
WHERE oferta = "designer")

Also, you can probably get rid of your subquery by joining:

此外,您可以通过加入来摆脱子查询:

SELECT COUNT(oferta_id_oferta) 
FROM `oferta_has_tags`, `oferta`
WHERE
    oferta_has_tags.oferta_id_oferta = oferta.id_oferta
    AND oferta.oferta = "designer"