问题背景:数据库内有两个表,user,message ,message表中含有useId外键,现在需要统计发的message超过2条的user,并按发的消息条数从高到低排序
SELECT user.userId, COUNT(msg.messageId) FROM user JOIN message as msg ON user.userId = msg.userId GROUP BY user.userId HAVING COUNT(msg.messageId) > 2 ORDER BY COUNT(msg.messageId) DESC
显示结果