关系型数据库 -- 1




题目描述经常看到问题,如何取出每组的前 N 条记录 原始数据idSNameClsNoScore1AAAAC1672BBBBC1553CCCCC1674DDDDC1655EEEEC1956FFFFC2577GGGGC2878HHHHC2749IIIIC25210JJJJC28111KKKKC26712LLLLC26613MMMMC26314NNNNC39915OOOOC35016PPPPC35917QQQQC36618RRRRC37619SSSSC35020TTTTC35021UUUUC36422VVVVC374 需要结果idSNameClsNoScore5EEEEC1951AAAAC1673CCCCC1677GGGGC28710JJJJC28114NNNNC39918RRRRC376 如上表所示,在已知表中求得每个 ClsNo 对应的 Score 最高的两个元组(可以并列) 解法法一select * from Table1 a where 2>(select count(*) from Table1 where ClsNo=a.ClsNo and Score>a.Score) order by a.ClsNo,a.Score desc  法二selec
#技术帖    #mysql    #sql    #技术分享   



京ICP备15018585号