【发布时间】:2011-04-19 14:43:22
【问题描述】:
我正在尝试在一个 sql 语句查询中获取今天、本月至今、年初至今的行数(输入)。但我不确定为什么它给我三个相同的值。 这是我的sql语句。
select BU,
count(CASE when a.date_added = trunc(sysdate) then (part) else '0' end)
as TodayQuotes,
count(CASE when a.date_added > last_day(add_months(sysdate,-1)) then (part) else '0' end)
as MTDQuotesValue,
COUNT(case when to_number(to_char(a.date_added,'yyyy'))='2011' then (part) else '0' end)
as YTDRegularValue
from articles
group by BU;
任何帮助将不胜感激
【问题讨论】:
-
为什么先转换
to_char,然后转换to_number,最后比较成字符串('2011')?