sql - 案例陈述同一列
问题描述
有一列,其中包含总计和小时的值,但我需要将组分成两列,例如
select
case
when A.TYPE = 'H'
then A.Value
end as "Hours",
Case
when A.TYPE != 'H'
then A.VALUE
end as "Total"
from a
这返回的是 2 列,但将其加倍不是衬里值。
Hours Total
2 null
null 20
解决方案
您的表格似乎有两行。如果您想要结果集中的一行,则需要聚合:
select max(case when A.TYPE = 'H' then A.Value end) as Hours,
max(case when A.TYPE <> 'H' then A.VALUE end) as Total
from a;
推荐阅读
- c# - 如何从C#中的字典值中提取数据
- c# - 使用 C# MongoDB 驱动程序在 for 循环中创建过滤器的布尔逻辑
- github - grep 文件版本并将其作为变量应用到 GitLab CI
- reactjs - UI 异构测试:React + 旧 JWT
- bash - bash: parsing F-key (F1-F10) in script
- python - %load_ext rpy2.ipython“致命错误:无法初始化 JIT”
- vuejs2 - 无法使用道具将对象传递给新路由
- python - 在python中按字符串过滤字典值
- typescript - React native TextInput 属性在“IntrinsicAttributes & IInput”类型上不存在
- visual-studio-code - 如何回到原来的终端设置?