检查为什么记录在 SQL 中返回两次

Check why record is returned twice in SQL

我有一个 inward_doc_tracking_hdr table,总共有 79 条记录。

但是当我 运行 在存储过程中做同样的事情时,我总共得到 80 条记录。

我查了一下计数,一条记录计数是2条。

我想知道为什么记录被返回了两次。

这里是查询:

Select  
    UserName, Document_Type, 
    count(Doc_No) docno,
    Doc_No, No_Of_Days_Doc_Pending, UserEmail,
    RA1_Email  -- User table  
from 
    MainTempTable
group by 
    UserName, Document_Type, Doc_No, No_Of_Days_Doc_Pending, 
    UserEmail, RA1_Email, Doc_No

更新

还有我下面的查询 returns 2 条记录。

Select   
             U.first_name + ' ' + U.last_name UserName,   
             TH.To_User,   
             TY.Type_desc Document_Type,   
             RA.mkey Reporting_To,   
             U.Email AS UserEmail,   
             RAU.Email AS RA1_Email,   
             RAU.first_name + ' ' + RAU.last_name RAName,   
             TH.Doc_No,   
             DATEDIFF(DAY,TH.LastAction_DateTime,GETDATE()) - DATEDIFF(WK,TH.LastAction_DateTime, GETDATE())   
                AS No_Of_Days_Doc_Pending  
            --INTO MainTempTable  
                from inward_doc_tracking_hdr TH   
                    inner join    
             user_mst U ON TH.To_User = U.mkey   
                inner join   
             emp_mst M ON M.mkey = U.employee_mkey   
                inner join   
            type_mst_a TY ON TY.master_mkey = TH.doc_type   
                inner join   
            emp_mst RA ON RA.mkey = M.Reporting_To   
                inner join    
                    user_mst RAU ON RAU.employee_mkey = RA.mkey   
            where   
                TH.Status_flag NOT IN (5,14) --- 5 for close, 14 for return   
                    and TH.To_user IS NOT NULL
                    and TH.To_User = 1019

这样做

Select  
UserName, Document_Type, 
 docno,
Doc_No, No_Of_Days_Doc_Pending, UserEmail,
RA1_Email  -- User table  
 from 
MainTempTable
 group by 
UserName, Document_Type,  No_Of_Days_Doc_Pending, 
UserEmail, RA1_Email, Doc_No

希望对您有所帮助

Count()