作连接多张表后,有很多重复记录,如何筛选,去掉重复记录
通过多张表连接查询,找出想要的记录,可是插叙结果中有很多重复记录
下面是我的查询语句,有点复杂,希望各位高手耐心看一下,帮我想出解决的办法
select transHeader.transnumber,transHeader.transNumberReal, -----运单流水号,公路运输单的单号
transHeader.transType,--运单类型
case when transHeader.TrainNumber is null then '(公路) ' + transType1.typename else '(铁路) ' + transType1.typename end as TransMode, ----运输类型,
trainNumber,CarriageNumber, -------车次,机次位
replace(convert(varchar(16),transHeader.DepartTime,120), '-0 ', '- ') as DepartTime,-----发车时间
transHeader.StartAddress,transHeader.EndAddress, -----对应的始发机构,终到机构
typelist1.typelistdesc1 as TailOrganization, ---运单运作机构
typelist2.typelistdesc1 as SignOrganization, ----运单签收机构
round(convert(float,isNull(ShipQty,0)),0) as ShipQty,round(convert(float,isNull(ShipWeight,0)),3) as ShipWeight,round(convert(float,isNull(ShipVolume,0)),3) as ShipVolume, ----件数,重量,体积
StartTime, -----开单时间
case when OperationMode= 'JTL ' and CarrierPickup=1 and CarrierDispatch=0 then '门到站 ' when OperationMode= 'JTL ' and CarrierDispatch=1 and CarrierPickup=0 then '站到门 '
when OperationMode= 'JTL ' and CarrierDispatch=1 and CarrierPickup=1 then '门到门 ' when OperationMode= 'JTL ' and CarrierDispatch=0 and CarrierPickup=0 then '站到站 '
else '非行邮门到门 ' end as 运作方式,
case transStatus when 5 then isnull(typelist7.typelistdesc1, ' ')+ '运输中 ' when 3 then isnull(typelist4.typelistdesc1, ' ')+ '已发送 '
when 7 then isnull(typelist5.typelistdesc1, ' ')+ '已接收 ' when 9 then isnull(typelist6.typelistdesc1, ' ')+ '已签收 ' else ' ' end as transStatus,
transHeader.Remark1,-----备注
transHeader.vendorName, ---供应商
case when replace(convert(varchar(10),transHeader.DeliverTime,120), '-0 ', '- ')= '1900-1-1 ' then ' '
else replace(convert(varchar(16),transHeader.DeliverTime,120), '-0 ', '- ') end as DeliverTime, ---派发时间
transHeader.FourgonNumber,---车厢号
transHeader.APayable,transHeader.realExpense,----应付,实付
replace(convert(varchar(16),transHeader.closeTime,120), '-0 ', '- ') as closeTime, -----签收时间
case when transHeader.APayable-transHeader.realExpense> 0 then ' <font color=red> '+convert(varchar(20),transHeader.APayable-transHeader.realExpense)+ ' </font> '
else convert(varchar(20),transHeader.APayable-transHeader.realExpense) end as notAPayable,-----未付红色显示
-- //滞留类型
case when transHeader.TrainNumber is null and transType1.typename= '基地提货 ' and transHeader.AddWho is