select a.creatdate,a.subcount,b.total,a.subcount*100/total from
(select creatdate,COUNT(0) subcount from test where [percent]>75 group by creatdate)a
,
(select creatdate,COUNT(0) as total from test group by creatdate)b where a.creatdate=b.creatdate
本文介绍了一个具体的SQL查询案例,展示了如何从数据库中选取特定日期的记录并计算百分比数据。通过两个子查询,分别获取满足条件的子集和全部数据的计数,最后通过连接操作将两部分数据合并,并计算出所关注的百分比。
select a.creatdate,a.subcount,b.total,a.subcount*100/total from
(select creatdate,COUNT(0) subcount from test where [percent]>75 group by creatdate)a
,
(select creatdate,COUNT(0) as total from test group by creatdate)b where a.creatdate=b.creatdate
4239

被折叠的 条评论
为什么被折叠?