zhuazhuqingchong 2015-07-22 15:23 采纳率: 0%
浏览 2635
已结题

数据库,求最小 group ,count,min

在Table中,我需要查出那个ID出现的频率最小,
select count(c1) from table where id=1,
select count(c1) from table where id=2
select count(c1) from table where id=3
select count(c1) from table where id=4,
最后查出来的结果理想是
0
1
2
3
不知道有没有好一点的思路,不想在代码里做个傻循环,需要注意的是ID可能为空
即select * from table where id=1有可能无结果集

  • 写回答

14条回答 默认 最新

  • threenewbee 2015-07-22 15:25
    关注

    select count(c1) as xx from table group by id order by xx

    评论

报告相同问题?