使用sql

时间:2018-04-27 14:02:53

标签: sql oracle

如何将以下格式的sql输出转换为下表?

Date(col 1) Name(col 2)  Value(col 3))
2018-03-05 A_SPACE       5534
2018-03-05 B_SPACE        34324
2018-03-06 A_SPACE       4645
2018-03-06 B_SPACE        435

预期格式

Date            A_SPACE     B_SPACE     
---             ---             ---         
2018-03-05      5534            34324   
2018-03-06      4645            435

2 个答案:

答案 0 :(得分:1)

如果您有,最简单的方法可能是条件聚合:

.alphabet {
  font-size: 80px;
  /*Below is not working...why?*/
  vertical-align: middle;
}

.letter-grid {
      display: flex;
}

.filter-item-grid {
    display: grid;
    display: -ms-grid;
    grid-template-columns: auto auto;
    justify-content: space-between;
    align-content: space-between;
}

.letter-grid__filter-item {
    display: grid;
    display: -ms-grid;
    grid-template-rows: repeat(3,auto);
    grid-auto-flow: column;
    margin-left: 24px;
}

如果您的表是查询的结果,那么您可以将类似的逻辑合并到查询中。

答案 1 :(得分:0)

试试这个。

SELECT * 
FROM tablename PIVOT( Max(value) FOR NAME IN('A_SPACE','B_SPACE')) 
ORDER BY dates;

演示:http://www.sqlfiddle.com/#!4/d97ee/23/0

如果您需要动态支点,请参阅这些文章。

https://technology.amis.nl/2006/05/24/dynamic-sql-pivoting-stealing-antons-thunder/
Dynamic pivot in oracle sql
dynamic columns in oracle using sql