我想从表中选择所有记录,且按计数分组大于5

时间:2019-05-21 23:48:22

标签: php mysql

我想从一张表中获取所有记录,其中agent_no = 70并按home_number,agent_no分组,count(*)> 1

SELECT 
*
FROM user_data
WHERE agent_no = 70
GROUP BY
  home_number,
  agent_no
HAVING COUNT(*) > 1

SQL查询:文档

SELECT 
*,
COUNT(*) AS count
FROM voters_data
WHERE booth_no = 70
GROUP BY
  hno,
  booth_no
HAVING COUNT(*) > 1 LIMIT 0, 25

MySQL说:文档

  

1064-您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获取正确的语法,以在第4行的“ COUNT(*)AS计数中使用来自选民数据的AS计数Where展位号= 70 GROUP BY hno,bo”

2 个答案:

答案 0 :(得分:1)

booth_no之后您缺少逗号

....
booth_no
COUNT(*) AS count
....

应该是

....
booth_no,
COUNT(*) AS count
....

答案 1 :(得分:0)

您需要返回这些字段。

req.session.jwt = jwt