我有一个表的结构如下。
task_id(pk)
task_title(varchar2)
task_due_date(date)
现在我想基于以下条件绘制图表。
我尝试使用Group By条件如下。
select (select count(TASK_ID) from rev$ta_task where (task_due_date >sysdate)) as notDue,
(select count(TASK_ID) from task where (task_due_date <sysdate)) as DuedMoreThan4Week,
(select count(TASK_ID) from task where (task_due_date +7<sysdate)) as DuedOneWeek,
(select count(TASK_ID) from task where (task_due_date +7<sysdate) and (task_due_date +30<sysdate)) as DuedFourWeek,
(select count(TASK_ID) from task where (task_due_date is null)) as noDueDate
from dual
我正在从中得到输出
NOTDUE DUEDMORETHAN4WEEK DUEDONEWEEK DUEDFOURWEEK NODUEDATE
4 4 2 0 2
但是要从中绘制图表,我们需要单列而不是多列的所有上述值,那么我该如何实现呢?有没有更好的解决方案呢?因为我是PLSQL的新手,所以我尽力编写更好的Query。
注意:我正在使用oracle 11g并将使用上面的查询来绘制Oracle-Apex中的图表。
你可以尝试制作一个UNION ALL
来制作它。
select 'NOTDUE' name,count(TASK_ID) cnt from task where (task_due_date >sysdate)
UNION ALL
select 'DUEDMORETHAN4WEEK',count(TASK_ID) from task where (task_due_date <sysdate)
UNION ALL
select 'DUEDONEWEEK',count(TASK_ID) from task where (task_due_date +7<sysdate)
UNION ALL
select 'DUEDFOURWEEK',count(TASK_ID) from task where (task_due_date +7<sysdate) and (task_due_date +30<sysdate)
UNION ALL
select 'NODUEDATE',count(TASK_ID) from task where (task_due_date is null)