我正在尝试在一个 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;
任何帮助将不胜感激
最佳答案
select BU,
sum(CASE when a.date_added = trunc(sysdate)
then 1
else 0
end ) as TodayQuotes,
sum(CASE when a.date_added > last_day(add_months(sysdate,-1))
then 1
else 0
end) as MTDQuotesValue,
sum(case when to_number(to_char(a.date_added,'yyyy'))='2011'
then 1
else 0
end) as YTDRegularValue
from articles
group by BU;
关于sql - 计算 SQL 中 case 语句的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5718220/