这是查询。closed_ts 是一个时间戳列。我想做的是,找出今天、本月、今年和本周有多少“关闭”。有一个更好的方法吗?
select table_id,
case
when trunc(closed_ts) = trunc(SYSDATE, 'DD') then 1
else 0
end as day_count,
case
when trunc(closed_ts) >= trunc(SYSDATE, 'MM') then 1
else 0
end as month_count,
case
when trunc(closed_ts) >= trunc(sysdate, 'YYYY') then 1
else 0
end as year_count,
case
when trunc(closed_ts) >= TRUNC(sysdate, 'IW') then 1
else 0
end as week_count
from myTable