我有一个表userInteret
,我想在用户之间选择最大的联系方式。
我试过这个问题:
SELECT nomInteretUser,idUser,COUNT(nomInteretUser) FROM `userInteret`
WHERE nomInteretUser IN('piano','flute','chien') GROUP BY idUser
但是当我尝试这个时,我想要这个COUNT的MAX:
SELECT MAX(COUNT(nomInteretUser))FROM userInteret
WHERE nomInteretUser IN('piano','flute','chien') GROUP BY idUser;
总是会出错:
MySQLarépondu:文档
1111 - 无效使用组功能
答案 0 :(得分:3)
SELECT idUser,COUNT(nomInteretUser) counts
FROM userInteret
WHERE nomInteretUser IN('piano','flute','chien')
GROUP BY idUser
ORDER BY counts DESC LIMIT 1
答案 1 :(得分:1)
SELECT MAX(num) FROM (
SELECT nomInteretUser,idUser,COUNT(nomInteretUser) as num FROM userInteret WHERE nomInteretUser IN('piano','flute','chien') GROUP BY idUser
) AS MYalias