ZKX's LAB

SQL中如何让重复数据也显示出来 sql显示重复数据

2021-04-26知识13

求sql显示(查询)不重复数据命令 必须有唯一标识列才能过滤重复,下面给你个思路:生成唯一id列:select id=identity(1,1),bianhao、name、jiage、chandi、shuliang into#tmp_tb from 表1查询显示name不重复的所有数据:select*from#tmp_tb t1 where not exists(select 1 from#tmp_tb t2 where t2.name=t1.name and t2.id)bianhao列为唯一标示列,显示大的小的都可以那直接查就可以了:select*from kucun t1 where not exists(select 1 from kucun t2 where t2.name=t1.name and t2.bianhao)

SQL查询重复数据0显示,条数不变! 求大侠帮忙 基于oracle,表名v(如果条件允许建一个自增列,用于唯一标识一条记录):select v1.a,b,c,dfrom(select rownum as rn,vv.*from v vv)v1,(select min(rownum)as rn from v group by a)v2where v1.rn=v2.rnunionselect v3.a,case when v3.b=v4.b then 0 else v3.b end as b,case when v3.c=v4.c then 0 else v3.b end as c,case when v3.d=v4.d then 0 else v3.b end as dfrom(select rownum as rn,vv.*from v vv)v3,(select v1.*from(select rownum as rn,vv.*from v vv)v1,(select min(rownum)as rn from v group by a)v2where v1.rn=v2.rn)v4where v3.rn<;>;v4.rnand v3.a=v4.a

sql重复数据只显示一条 如果只是按你的结果得到数据,则语句是:select 名字,max(金额)金额from 表group by 名字但感觉金额应该是统计的,比如张三显示230,则应该是select 名字,sum(金额)金额\\from 表group by 名字

随机阅读

qrcode
访问手机版