【发布时间】:2020-09-03 16:55:42
【问题描述】:
我试图在查询中进行分组,但每次数据有 0 时,分组不会显示整行。我该如何解决这个问题?
这是常规查询
select
COUNT(DISTINCT sr.sr_number) AS NEW_CASES
FROM table sr
where
sr.business_unit in('BU1')
and OPENED_DATE < trunc(current_Date)
and OPENED_DATE > trunc(current_date -2)
and sr.status = 'Open'
输出是
NEW_CASES
0
但是当我做一个分组时。整行都不见了。
select
COUNT(DISTINCT sr.sr_number) AS NEW_CASES,
sr.business_unit
FROM table sr
where
sr.business_unit in('BU1','BU2','BU3' )
and OPENED_DATE < trunc(current_Date)
and OPENED_DATE > trunc(current_date -2)
and sr.status = 'Open'
group by sr.business_unit
按输出分组是
New_CASES BUSINESS_UNIT
200 BU2
300 BU3
期望的输出:
New_CASES BUSINESS_UNIT
0 BU1
200 BU2
300 BU3
【问题讨论】:
-
您使用的是 Oracle 还是 Teradata?请正确标记。
-
数据库是 teradata 但通过 Oracle SQL 开发人员
标签: sql group-by count teradata