【问题标题】:convert row output to column in oracle在oracle中将行输出转换为列
【发布时间】:2019-12-06 17:20:26
【问题描述】:

with cte1 as 
(
select count(*) as count_emp from emp; 
),
 cte2 as 
(
select count(*)  as count_dept from dept; 
),
 cte3 as 
(
select count(*)  as count_hr  from hr; 
)
select count_emp,count_dept,count_hr from cte1,cte2,cte3;

我想在一列中输出三行。 有关更多详细信息,请参见图片。

【问题讨论】:

    标签: sql oracle oracle11g oracle10g


    【解决方案1】:

    使用union all:

    select count_emp from cte1
    union all
    select count_dept from cte2
    union all
    select count_hr from cte3;
    

    请注意,结果不保证按任何特定顺序排列。我强烈建议您标记行:

    select 'emp', count_emp as cnt from cte1
    union all
    select 'dept', count_dept from cte2
    union all
    select 'hr', count_hr from cte3;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多