sql - Oracle:将列转置为行
问题描述
我有下表中的数据
bins | pro
-------------
1 | 0.10
2 | 0.05
3 | 0.78
4 | 0.20
5 | 0.82
6 | 0.45
我需要一个带有此结果的查询:
1 | 2 | 3 | 4 | 5 | 6
-------------------------------------------------
0.10 | 0.05 | 0.78 | 0.20 | 0.82 | 0.45
解决方案
对于固定的 bin 列表,您可以进行条件聚合:
select
max(case when bins = 1 then pro end) as bins1,
max(case when bins = 2 then pro end) as bins2
...
max(case when bins = 6 then pro end) as bins6
from mytable
推荐阅读
- python - 计算 AUC 曲线时如何创建阈值?
- python - 'Button' 对象在第二次使用时不可调用
- java - Android Studio - webview下的广告不加载
- reactjs - 将 react-admin 添加到现有项目 - resourceState 未定义
- rust - 是否可以让 wasm-bindgen 忽略 impl 中的某些公共功能?
- elixir - 混合 ecto.create bcrypt_elyxir 和 nmake 错误
- javascript - 为什么我们应该使用 import React from 'react'
- javascript - 是否可以更改重定向页面的比例?
- f# - 可取消 F# 异步主程序,传播异常
- c# - 传递给 ViewDataDictionary 的模型项是 X[] 类型,但是这个 ViewDataDictionary 实例需要 X 类型的模型项