博客
关于我
GROUP BY在SQL查询语句中的使用
阅读量:372 次
发布时间:2019-03-04

本文共 859 字,大约阅读时间需要 2 分钟。

表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;

 

 

 

转载地址:http://hsje.baihongyu.com/

你可能感兴趣的文章
LeetCode Add Two Numbers
查看>>
LeetCode AutoX 安途智行专场竞赛题解
查看>>
LeetCode Best Time to Buy and Sell Stock with Cooldown
查看>>
LeetCode Find Minimum in Rotated Sorted Array
查看>>
LeetCode House Robber
查看>>
LeetCode Lowest Common Ancestor of a Binary Tree
查看>>
LeetCode Most Common Word 最常见的词
查看>>
LeetCode OJ:Integer to Roman(转换整数到罗马字符)
查看>>
LeetCode OJ:Merge k Sorted Lists(归并k个链表)
查看>>
leetcode Plus One
查看>>
LeetCode shell 题解(全)
查看>>
LeetCode Text Justification
查看>>
leetcode Valid Parentheses
查看>>
Leetcode | Simplify Path
查看>>
LeetCode – Refresh – 4sum
查看>>
LeetCode – Refresh – Valid Number
查看>>
leetcode — edit-distance
查看>>
LeetCode 中级 - 有序链表转换二叉搜索树(109)
查看>>
leetCode 字符串反转
查看>>
LeetCode 无重复字符的最长子串 获取字符串中不重复的子串最大长度
查看>>