【问题标题】:default rows from select query选择查询的默认行
【发布时间】:2020-08-06 00:38:24
【问题描述】:

我有一个带有 group by 子句的选择查询(Oracle 数据库),如果所有必需的数据都存在,则需要返回 4 行。它完美地工作。 即使不存在数据,如何编写返回相同 4 行的选择查询。如果没有数据,我希望字段 C 的值为零。请告知。谢谢。

【问题讨论】:

  • 您的数据是什么样的?您使用的查询是什么?

标签: sql oracle


【解决方案1】:

这是你想要的吗?

select x.a, x.b, count(t.a)
from (select 'ORG-1' as A, 'CAR' as b from dual union all
      select 'ORG-1' as A, 'BIKE' as b from dual union all
      select 'ORG-2' as A, 'CAR' as b from dual union all
      select 'ORG-2' as A, 'BIKE' as b from dual 
     ) x left join
     t
     on x.a = t.a and x.b = t.b
group by x.a, x.b
      

【讨论】:

  • 我在下面尝试过的查询。 select b.org, a.status, count(*) from (select 'ORG-1' as A1, 'CAR' as B1 from dual union all select'ORG-1' as A1, 'BIKE' as B1 from dual union所有选择'ORG-2'作为A1,'CAR'作为B1从双重联合所有选择'ORG-2'作为A1,'BIKE'作为B1从双重)X左加入vchlschdl a on X.A1 = a.A1和X.B1=a.B1 left join vchlmstr b on a.servers=b.servers group by X.A1,X.B1
  • @user3166984 。 . .您应该使用该查询获得所有四行。
猜你喜欢
  • 2010-10-28
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多