SQL计数 - 不工作

时间:2011-10-20 18:13:48

标签: mysql sql count

我正在尝试这段代码:

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

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

如果我删除了COUNT字,我会得到两个结果。

有什么问题?

2 个答案:

答案 0 :(得分:60)

不要放置空格

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

答案 1 :(得分:7)

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

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

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

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