请教大家一个关于去除重复项的问题!
我在做查询时需要用到 a、b、c,三个相关联表的数据。但是查询后b表的数据有重复的 通过where 限制后还是有重复数据产生。如下
select distinct(a.[StaffID]),b.[staffJob] ,c.[staffPart],
convert(varchar(100),a.[EmployTime],23) as [EmployTime] from [Staffs]
as a,[staffJob] as b,[staffPart] as c where a.[StaffID]=b.[StaffID] and a.[staffPartID]=c.[staffPartID]
重复项为b表的数据项,请问该如何让b表没有重复数据
------解决方案--------------------select distinct(a.[StaffID]),b.[staffJob] ,c.[staffPart],
convert(varchar(100),a.[EmployTime],23) as [EmployTime]
from [Staffs]
as a,[staffJob] as b,[staffPart] as c
where a.[StaffID]=b.[StaffID] and a.[staffPartID]=c.[staffPartID]
and BINARY_CHECKSUM([staffJob],[staffPart]) in(
select BINARY_CHECKSUM([staffJob],[staffPart])
from staffPart
group by BINARY_CHECKSUM([staffJob],[staffPart]))
------解决方案--------------------select distinct(a.[StaffID]),b.[staffJob] ,c.[staffPart],
convert(varchar(100),a.[EmployTime],23) as [EmployTime]
from [Staffs]
as a,[staffJob] as b,[staffPart] as c
where a.[StaffID]=b.[StaffID] and a.[staffPartID]=c.[staffPartID]
and BINARY_CHECKSUM([staffJob],[staffPart]) in(
select BINARY_CHECKSUM([staffJob],[staffPart])
from staffPart
group by BINARY_CHECKSUM([staffJob],[staffPart])
having count(*)=1)--取没有重复的
------解决方案--------------------如果C表有多于一项满足a.[staffPartID]=c.[staffPartID],
那么B显示出来肯定会有重复,这也是正常合理的。
除非你愿意舍弃掉一些C表的记录
------解决方案--------------------select distinct(a.[StaffID]),b.[staffJob] ,c.[staffPart],
convert(varchar(100),a.[EmployTime],23) as [EmployTime] from [Staffs]
as a,(select distinct * from [staffJob]) as b,[staffPart] as c where a.[StaffID]=b.[StaffID] and a.[staffPartID]=c.[staffPartID]
这样看看?