用sql语句实现去重计数查询

最近开发acm队员cf数据统计查询系统(https://github.com/liuyong0076/ACMER),需要对每个学号完成的cf题数进行计数。

首先使用cf提供的api将数据抓取并存入数据库,其中有学号stuNO,比赛ID-cid,题目编号index,判题结果stutus几个关键字段。

难点是要对同一个学号,同一个比赛id,同一道题的多次正确提交进行去重。

最终使用嵌套查询实现,代码如下:

select a.stuNo, count(*) from 
(
select stuNO, cid, `index`, statu,count(*) from acmerdata_cfcontest where status='OK' GROUP BY stuNO, cid, `index`, status HAVING count(*)<2
) a
group by a.stuNo;
posted @ 2020-03-06 20:43  liuyong0076  阅读(4733)  评论(0编辑  收藏  举报