需要帮助创建SQL查询。
以下是我用于SQL查询的表格。
Task
表(指定不同的任务)Task Type
表(任务的名称和类型)Work
表(获取与不同工作ID关联的任务)和工作类型(定义工作类型和工作类别)表工作类型表下的类别是" D"," I"," A"
以下是我的查询
SELECT SUM(t.cost) AS Cost,
wt.jobCategory AS Cat,
TO_CHAR(t.taskStart, 'MON-YY') AS taskDate
FROM task t,
WORK w,
work_type wt
WHERE w.workId = t.jobId
AND w.workType IN(a,b,c,d)
AND t.taskType IN(1,2,4,5,6,7,8)
AND wt.workType = w.workType
AND t.taskStart >= to_date('01/04/2013 01:00:00', 'dd/mm/yyyy hh24:mi:ss')
AND t.taskStop < to_date('03/04/2014 23:59:59', 'dd/mm/yyyy hh24:mi:ss')
GROUP BY TO_CHAR(t.taskStart, 'YYYYMM'),
TO_CHAR(t.taskStart, 'MON-YY'),
wt.workCategory
ORDER BY TO_CHAR(t.taskStart, 'YYYYMM') ASC;
查询的输出是
##Cost Cat TaskDate##
-----------------------------------------
26243.13 D MAY-13
6716.7 A MAY-13
14839.55 D JUN-13
4653.61 I JUN-13
59209.46 D JUL-13
10018.12 I JUL-13
22976.54 D AUG-13
7363.35 I AUG-13
9256.15 D SEP-13
4054.83 A SEP-13
371.1 D OCT-13
44.64 I OCT-13
480 A NOV-13
73618.24 D NOV-13
14293.47 I NOV-13
如果没有指定月份的值,我可以帮助我解决上述查询,我希望类别值(cat)为0
预期输出就像
##Cost Cat TaskDate##
26243.13 D MAY-13
6716.7 A MAY-13
0 I MAY-13
14839.55 D JUN-13
4653.61 I JUN-13
0 A JUN-13
59209.46 D JUL-13
10018.12 I JUL-13
0 A JUL-13
22976.54 D AUG-13
7363.35 I AUG-13
0 A AUG-13
9256.15 D SEP-13
4054.83 A SEP-13
0 I SEP-13
371.1 D OCT-13
44.64 I OCT-13
0 A OCT-13
480 A NOV-13
73618.24 D NOV-13
14293.47 I NOV-13
感谢您的帮助。