我没有得到独特的数据

时间:2015-08-13 07:09:55

标签: sql

我的查询结果出错了。

我要做的是获取unique数据。

Employeenames会有所不同,但会从columns的其余部分获取相同的数据。

 SELECT A.MONTH
        ,(
            SELECT SUM(AMOUNT)
            FROM V_HR_PP_PROCESS_DATA
            WHERE EMPLOYER_CODE = A.EMPLOYER_CODE
                AND TAX_YEAR = A.TAX_YEAR
                AND PROCESS_MONTH = A.MONTH
                AND EMPLOYEE_ID IN (
                    SELECT EMPLOYEE_ID
                    FROM I_HR_EMP_EMPLOYMENT_DTL
                    WHERE EMPLOYER_CODE = A.EMPLOYER_CODE
                        AND CONTRACT_TERM = 'P'
                    )
                AND PROCESS_MONTH BETWEEN 1
                    AND 10
                AND PD_CODE = 'Z500'
            ) AS GROSS_PERMANENT
        ,b.EMPLOYEE_NAME AS employeename
        ,(
            SELECT SUM(AMOUNT)
            FROM V_HR_PP_PROCESS_DATA
            WHERE EMPLOYER_CODE = A.EMPLOYER_CODE
                AND TAX_YEAR = A.TAX_YEAR
                AND PROCESS_MONTH = A.MONTH
                AND EMPLOYEE_ID IN (
                    SELECT EMPLOYEE_ID
                    FROM I_HR_EMP_EMPLOYMENT_DTL
                    WHERE EMPLOYER_CODE = A.EMPLOYER_CODE
                        AND CONTRACT_TERM = 'F'
                    )
                AND PROCESS_MONTH BETWEEN 1
                    AND 10
                AND PD_CODE = 'Z500'
            ) AS GROSS_CASUAL
    FROM I_HR_SYS_DATE_MONTHLY A
    INNER JOIN I_HR_EMPLOYEE_MASTER b ON b.EMPLOYER_CODE = A.EMPLOYER_CODE

1 个答案:

答案 0 :(得分:0)

最后添加

if yada yada
    x = f(x)   %// If you don't have anything here, you should use "if ~yada yada"
               %// instead of "else"
else
    while k>1 && x == true  %// BTW: Lower case t in true 
        x = g(y)  %// I hope you have something more than "k=k-1" in this loop
        k = k-1;
    end
end
选择

group by A.MONTH,A.TAX_YEAR,A.EMPLOYER_CODE, b.EMPLOYEE_NAME

试试这个

distinct