查看一些特定sql需求的书写

user表,5个人abcde,  content表10篇文章,一个人对应两篇文章,有 time字段,查询出五个人的最新文章。

select a.id,a.SName,a.ClsNo,a.Score
from Table1 a left join Table1 b on a.ClsNo=b.ClsNo and a.Score<b.Score
group by a.id,a.SName,a.ClsNo,a.Score
having count(b.id)<2
order by a.ClsNo,a.Score desc

SELECT a.id ,b.content FROM table1 a LEFT JOIN content b ON a.id = b.uid GROUP BY a.id ORDER BY b.time
原文地址:https://www.cnblogs.com/wicub/p/5645337.html