我有一张表,其结构如下。
task_id(pk)
task_title(varchar2)
task_due_date(date)
现在我想根据以下条件绘制图表。
我尝试使用分组条件如下。
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的新手,所以我尽力编写了更好的查询。
注意:我正在使用oracle 11g,将使用上面的查询来绘制图表 Oracle-Apex。
答案 0 :(得分:1)
您可以尝试制作一个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)