【问题标题】:How to create select query to view multiple columns for values?如何创建选择查询以查看多个列的值?
【发布时间】:2016-10-29 02:14:04
【问题描述】:
COUNT(DATECREATED)
88708
26625
17092

如何创建一个选择查询,以将单个列中的这三个值作为不同的列名查看

COUNT(DATECREATED)       COUNT(DATECREATED)            COUNT(DATECREATED)
88708                         26625                           17092
88708
88708

【问题讨论】:

  • COUNT(DATECREATED) ----88708 ----26625 --- 17092
  • 为什么88708 出现三次,为什么不出现26625
  • 计数(日期创建)计数(日期创建)计数(日期创建)88708 26625 17092
  • Prdp @我需要这样的输出

标签: sql oracle select view oracle11g


【解决方案1】:

如果您只想要 1 行以 3 行作为列,请使用它。这里col 是您的count 语句的别名。

with tbl as 
(select rownum as rno,col from
    (your existing query) t
)
select (select col from tbl where rno=1) col1 , 
    (select col from tbl where rno=2) col2, 
    (select col from tbl where rno=3 ) col3 
from dual

如果有更多行并且您想将它们用作列,请阅读Dynamic pivot in Oracle,您会得到答案。

【讨论】:

    【解决方案2】:

    我终于喜欢上了。。谢谢大家的快速回复

    选择 sum(colname) 作为别名,sum(colname) 作为别名,sum(colname) 作为别名 from (select count(colname) as colname,0 as colname,0 as colname from cof 联合所有 select 0,count(colname),0 from cof where colname is not null 联合所有 select 0,0,count(colname) from cof where colname is not null);

    【讨论】:

      猜你喜欢
      • 2019-12-10
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2016-07-28
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      相关资源
      最近更新 更多