Oracle sql查询以按几列分组获取记录
我需要从Oracle中的几个表中获取记录。 查询我有如下返回记录Oracle sql查询以按几列分组获取记录,sql,oracle,Sql,Oracle,我需要从Oracle中的几个表中获取记录。 查询我有如下返回记录 假设您当前的查询工作正常,那么它在Oracle中似乎无效,您可以将其用作CTE并获得所需的结果。例如: with x (appcount, typeid, name) as ( -- your current query here... ) select sum(case when typeid = 1 then 1 else 0 end) as type1, sum(case when typeid = 2 the
假设您当前的查询工作正常,那么它在Oracle中似乎无效,您可以将其用作CTE并获得所需的结果。例如:
with
x (appcount, typeid, name) as (
-- your current query here...
)
select
sum(case when typeid = 1 then 1 else 0 end) as type1,
sum(case when typeid = 2 then 1 else 0 end) as type2,
sum(case when typeid = 3 then 1 else 0 end) as type3,
name
from x
group by name
直接在查询中使用分组依据和大小写,如下所示:
select
sum(case when t3.id = 1 then 1 end) as type1,
sum(case when t3.id = 2 then 1 end) as type2,
sum(case when t3.id = 3 then 1 end) as type3,
t2.name
from t0 ra
Join table1 t1 on t1.id = ra.id
Join table2 t2 on t2.id = ra.id
join table3 t3 on t3.id = ra.typeid
where t1.column1 = 1
Group by t2.name;
干杯 您确定第一个查询在Oracle中有效吗?您没有GROUPBY子句,但某些列是聚合的…如果我不清楚我的问题,很抱歉。但Tejash的回答对我有效。