sql - SQL 如何修改这张表
问题描述
如何在sql中获取此表:
id cunsumption_bhd cunsumption_metha
id1 21.0 10.2
从此表中:
id type cunsumption
id1 bhd 21.0
id1 metha 10.2
解决方案
一种方法是条件聚合:
select max(case when type = 'bhd' then consumption end) as consumption_bhd,
max(case when type = 'metha' then consumption end) as consumption_metha
from t;
推荐阅读
- oracle - 需要澄清一下oracle的UTL_FILE包
- tsql - T-SQL,仓库原理,两个数据集使用FIFO合并为一个数据集
- c++ - 通过 WPE 上的 WebKit Web 扩展进行 DOM 注入
- c++ - 如何与程序的其余部分同时显示计时器?
- sql - 基于用户定义的 WHERE 子句
- c++ - 从字符串中删除重复的单词
- c# - 如何将 byte[] 转换为 GameObject?(统一安卓)
- azure - 如何在不启用租户范围访问的情况下配置服务主体和 PowerBI.com 以对选定工作区进行 API 访问?
- javascript - 将 css 变量导入主题的根选择器
- spring-boot - Spring-Boot、JPA 事务和 RabbitMQ 接收器 => 不一致的数据库状态