数据库 统计重复数量 sql

数据库 统计重复数量 sql,第1张

select id,sum(case when name='红茶' then 1 else 0 end) as '红茶' 
,sum(case when name='绿茶' then 1 else 0 end)
 as'绿茶'  
,sum(case when name='黄茶' then 1 else 0 end) as '黄茶' from tablename
group by id

给个思路你吧。先给表排列序号(类似ID来使用),然后写个循环,记录Failed次数,并且对比UUT_Staus值是否Failed,如果不为Failed,并且Failed大于1的,则把上一条记录插入到临时表中,最后再查找临时表。

declare @ChongfuCount int,@TotalCount int
select @ChongfuCount=count() from
(select a2,count() as cnt from a group by a2 having count()>1) t
select @TotalCount =count(a2) from a
重复率 = @ChongfuCount10/@TotalCount
--但你说到分组 你把题目说的清晰点
select b1 from b,a
where aa1=ba1
group by b1


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13404851.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-29
下一篇 2023-07-29

发表评论

登录后才能评论

评论列表(0条)

保存