在比较2个表时,在sql查询中记录两次

时间:2018-03-26 13:03:39

标签: sql sql-server

我有一个2表,员工表和工资流程表。一旦我处理了工资相应的员工详细信息,我就会插入工资流程表。

我有这样的查询:

SELECT
    employee_tbl.emp_maxid,
    emp_name AS 'Employee Name',
    Designation_tbl.Des_Name AS Designation,
    emp_LabourID,
    emp_IBAN,
    emp_monthlysalary AS Salary,
    0 AS commission,
    emp_monthlysalary  AS Total,
    --ISNULL(s.Salary - sum(S.Paid), emp_monthlysalary) AS Total,
    isnull(s.balance,0) as balance
FROM 
    dbo.employee_tbl
INNER JOIN 
    dbo.Designation_tbl ON Designation_tbl.Des_id = employee_tbl.Des_id
LEFT JOIN 
    SalaryProcessLog_tbl S ON S.emp_maxid = employee_tbl.emp_maxid
WHERE 
    (emp_deleted = 0
     OR emp_deleted IS NULL)
    AND employee_tbl.emp_maxid NOT IN (SELECT emp_maxid
                                       FROM SalaryProcessLog_tbl 
                                       WHERE CAST(SalaryMnth AS DATE) = '2018-04-26')
GROUP BY 
    employee_tbl.emp_maxid, dbo.employee_tbl.emp_name, Designation_tbl.Des_Name,
    employee_tbl.emp_LabourID, emp_IBAN,emp_monthlysalary, 
    s.Salary, s.balance

我的输出是这样的:

enter image description here

在输出中,jaseem的记录显示两次,但在我的SalaryProcessLog_tbl中,该记录仅存在于一个特定月份。

我的查询有什么问题?

0 个答案:

没有答案