消除SQL Server 2008查询的重复记录

时间:2017-10-13 03:55:35

标签: sql-server

我读了许多与我的问题相关的类似标题,但我不能申请我的案子。 这是我的问题:

select 
    d._LINE_NO, a._PROCESS_INST_NO, a._ISSUER, a._ISSUE_DATE,
    d._PROCESS_CONTENTS, d._OPT_DIVISION, 
    b._GOODS_CD, b._GOODS_NAME,b._QTY,
    a._Order_No, c._GOODS_CD, c._GOODS_NAME,a._NOTE,
    d._LINE_NO + 1 as Proc_Step_No,
    count(*) over () as Total_Rows
from  
    [ENVNDIVDB].[dbo].[TBL_PROC_PH] a
inner join 
    [ENVNDIVDB].[dbo].[TBL_PROC_PM] b on b._PROCESS_INST_NO = a._PROCESS_INST_NO
inner join 
    [ENVNDIVDB].[dbo].[TBL_PROC_PMS] c on c._PROCESS_INST_NO = a._PROCESS_INST_NO
inner join 
    [ENVNDIVDB].[dbo].[TBL_PROC_PN] d on d._PROCESS_INST_NO = a._PROCESS_INST_NO
where 
    a._PROCESS_INST_NO = '610416'

结果如下:

enter image description here

重复了04次。 (见_PROCESS_CONTENT) 以下是Process Inst No:610416的原始数据

enter image description here

我的问题是如何消除重复的记录

提前多多感谢。

1 个答案:

答案 0 :(得分:0)

我找到了自己的解决方案:

=SUMIFS($D$2:$D$9,$A$2:$A$9,G2,$C$2:$C$9,"<>LP CA Meal Penalty",$C$2:$C$9,"<>LP CA Rest Break Penalty")
or
=SUMPRODUCT(($D$2:$D$9)*($A$2:$A$9=G2)*($C$2:$C$9<>"LP CA Meal Penalty")*($C$2:$C$9<>"LP CA Rest Break Penalty"))