急求在线等!!简单啊!
select distinct k.spmch,z.lxr,z.lxrdh,z.dzhdh,x.danjbh
from int_ddhz as z,spkfk as k,int_ddmx as x
where x.spid =k.spid and z.danjbh =x.danjbh and dspcode like 'J%'
为什么 spmch还是有重复的
[解决办法]
--这个肯定没重复的select distinct k.spmch from int_ddhz as z,spkfk as k,int_ddmx as x where x.spid =k.spid and z.danjbh =x.danjbh and dspcode like 'J%'--这是表示 k.spmch + z.lxr + z.lxrdh + z.dzhdh+x.danjbh 记录不重复select distinct k.spmch,z.lxr,z.lxrdh,z.dzhdh,x.danjbhfrom int_ddhz as z,spkfk as k,int_ddmx as x where x.spid =k.spid and z.danjbh =x.danjbh and dspcode like 'J%'
[解决办法]
select * from (select ROW_NUMBER() over(partition by k.spmch,z.lxr,z.lxrdh,x.danjbh order by id) as rowindex,* from mytest1) as a ,spkfk k, int_ddmx x where rowindex=1 and x.spid =k.spid and z.danjbh =x.danjbh and dspcode like 'J%'
[解决办法]
select distinct k.spmch,z.lxr,z.lxrdh,z.dzhdh,x.danjbh
from int_ddhz as z,spkfk as k,int_ddmx as x
where x.spid =k.spid and z.danjbh =x.danjbh and dspcode like 'J%'
这里用到的distinct去重复是指将 select 后所有列都重复的去掉,并不是去掉单独一列的重复
如果
select distinct b.spmch
from ..
where ..
这样倒是去掉spmch列的重复数据。
去掉重复有很多方法,楼主可以查查看,用标识列,时间字段等 not exists , max min ,row_number 等。
[解决办法]
这个应该是后面字段有重新的数据类型,所以这样的吧。
可以看看表中的数据,然后选择去重的方法。
[解决办法]
你把需求理解错了,你的这个DISTINCT 是在你SELECT 后面的所有列都不重复。
要想只第一列不重复,就得分组查询,后面的显示最大或最小,或平均值
[解决办法]