如何在以下查询中使用distinct

时间:2013-04-09 10:56:33

标签: oracle9i

CODE

SELECT            T_LEAVEAPPLY.I_EMPID, T_LEAVETYPE_MS.I_LEAVETYPE, T_LEAVEALLOCATION_MS.I_ALLOTTEDDAYS AS OPENINGBALANCE, EXTRACT(DAY
FROM T_LEAVEAPPLY.I_REQDATE) AS Dates, T_APPROVAL.I_CATEGORYNAME, T_LEAVEAPPLY.NOD,
T_LEAVEALLOCATION_MS.I_LASTUPDATED, T_EMPLOYEE_MS.I_EMPNAME 
FROM              T_LEAVEAPPLY 
INNER JOIN        T_APPROVAL ON T_APPROVAL.I_EMPID = T_LEAVEAPPLY.I_EMPID AND T_APPROVAL.I_REQDATE = T_LEAVEAPPLY.I_REQDATE AND T_APPROVAL.I_APPROVALSTATUS = T_LEAVEAPPLY.I_STATUS 
INNER JOIN        T_LEAVEALLOCATION_MS ON T_LEAVEALLOCATION_MS.I_EMPID = T_APPROVAL.I_EMPID AND T_LEAVEALLOCATION_MS.I_EMPID = T_LEAVEAPPLY.I_EMPID AND T_LEAVEALLOCATION_MS.I_LEAVETYPEID = T_LEAVEAPPLY.I_LEAVETYPEID
INNER JOIN        T_LEAVETYPE_MS ON T_LEAVETYPE_MS.I_LEAVETYPEID = T_LEAVEAPPLY.I_LEAVETYPEID AND T_LEAVETYPE_MS.I_LEAVETYPEID = T_LEAVEALLOCATION_MS.I_LEAVETYPEID
INNER JOIN        T_EMPLOYEE_MS ON T_EMPLOYEE_MS.I_EMPID = T_LEAVEAPPLY.I_EMPID
WHERE            (T_LEAVEAPPLY.I_EMPID = '9') AND (EXTRACT(MONTH FROM  T_LEAVEALLOCATION_MS.I_LASTUPDATED) = '3') AND (EXTRACT(YEAR FROM  T_LEAVEALLOCATION_MS.I_LASTUPDATED) = '2012') AND (EXTRACT(MONTH FROM   T_APPROVAL.I_REQDATE) = '3') AND (EXTRACT(YEAR FROM T_APPROVAL.I_REQDATE) = '2012') AND (EXTRACT(YEAR FROM T_LEAVEALLOCATION_MS.I_LASTUPDATED) = '2012')
ORDER BY T_LEAVEAPPLY.I_REQDATE DESC

输出

9获得休假10 28 LEAVE 2 3/9/2012

9病假8 19 LEAVE 2 3/9/2012

9临时休假10 17 LEAVE 1 3/9/2012

9临时休假10 2 LEAVE 2 3/9/2012

1 个答案:

答案 0 :(得分:0)

如果您没有在SELECT DISTINCT子句中包含它,则不能按I_REQDATE进行排序。