MySQL错误代码1111:无效使用组功能

时间:2018-03-06 19:41:57

标签: mysql mysql-workbench

当我尝试打印不跟随任何人的名人时,我收到错误代码1111。

user (email, password, name, date_of_birth, address, type)
primary key(email)

celebrity (email, website, kind)
primary key(email)

follow (follower,followee)
primary key(follower,followee)
foreign key(follower) references user(email)
foreign key(followee) references user(email))

SELECT DISTINCT(u.name)
FROM follow as f, user as u, celebrity as c
WHERE u.email = c.email and (0 > COUNT(f.followee))
ORDER by name DESC

1 个答案:

答案 0 :(得分:0)

您不能使用未在组

中提及的聚合功能的列

如果要检查聚合函数结果,则必须使用having而不是where

所以你应该使用

  SELECT u.name
  FROM follow as f, user as u, celebrity as c
  WHERE u.email = c.email
  GROUP BY  u.names
  having  0 > COUNT(f.followee)

  ORDER by name DESC

(但是0&CO; COUNT(f.followee)是没有意义的,你可能需要另一个检查计数条件,而且你的连接子句似乎还没有完成)