GROUP BY在SQL查询语句中的使用

表content

"ID""title""content""User_ID""Type_ID""Hits""time""tag"

表type

"ID""typeName"

表users

"ID""UserName"

SQL查询语句实现“按某类统计按文章数量给用户排名”

SELECT UserName, aa.ContentCount
FROM [SELECT content.User_ID, Count(content.User_ID) AS ContentCount
FROM content, type
WHERE (((type.ID)=1) AND ((content.Type_ID)=[type].[id]))
GROUP BY content.User_ID
ORDER BY Count(content.User_ID) DESC]. AS aa, Users
WHERE Users.id=aa.User_ID;

SQL查询语句实现“统计按文章数量给用户排名”

SELECT UserName, aa.ContentCount
FROM [SELECT content.User_ID, Count(content.User_ID) AS ContentCount
FROM content, type
WHERE (content.Type_ID)=[type].[id]
GROUP BY content.User_ID
ORDER BY Count(content.User_ID) DESC]. AS aa, Users
WHERE Users.id=aa.User_ID;

SQL查询语句实现“按用户统计文章点击率排名”

SELECT Sum(content.Hits) AS Hits之总计, content.User_ID
FROM content
GROUP BY content.User_ID
ORDER BY Sum(content.Hits) DESC;

你可能感兴趣的:(sql)