我需要满足以下要求
• Overdue
o This Week (Count)
o Past 3 Weeks (Count)
o Beyond 3 Weeks (Count)
• Due
o This Week (Count)
o Within 3 Weeks (Count)
o Beyond 3 Weeks (Count)
我尝试了以下查询
select to_date('05-MAY-17') > sysdate-6 and
to_date('05-MAY-17') < sysdate-6 then 'Y'
else 'N' from dual;
这里我有一周的硬编码..我不确定这是对的吗?请建议我更好的方式来满足我的要求。
提前致谢。
答案 0 :(得分:1)
据推测,你应该像图书馆应用程序一样查询表格。所以你需要的是像这堆条件计数:
select
count( case when due_date < sysdate
and due_date > sysdate-7 then 1 end ) overdue_one_week
, count( case when due_date <= sysdate-7
and due_date > sysdate-21 then 1 end ) overdue_three_week
, count( case when due_date <= sysdate-21 then 1 end ) overdue_longer
, count( case when due_date >= sysdate
and due_date < sysdate+7 then 1 end ) due_this_week
, count( case when due_date >= sysdate+7
and due_date < sysdate+21 then 1 end ) due_three_weeks
, count( case when due_date >= sysdate+21 then 1 end ) due_beyond_three_weeks
from library_loans
/