Mysql group by 中行转列
来源:互联网 发布:mac设置iphone铃声2017 编辑:程序博客网 时间:2024/05/01 06:06
我们在进行group by 的时候,有些列,我们不想进行聚合,比如上表的p,当我对match_id,expert_id,进行group by时,我想把p的值转成列类似于这样
也就是行转列,这时用到case when,语句如下
select match_id,expert_id,
sum(case parent_id WHEN 1 then p end) p1,
sum(case parent_id WHEN 2 then p end) p2,
sum(case parent_id WHEN 3 then p end) p3,
sum(case parent_id WHEN 4 then p end) p4,
sum(case parent_id WHEN 5 then p ELSE 0 end) p5,
sum(case parent_id WHEN 6 then p ELSE 0 end) p6,
sum(case WHEN parent_id is null then p ELSE 0 end) p7
from Table group by match_id,expert_id;
这句话表示对expert_id,match_id进行group by ,用case when 对p进行分类处理,通过parent_id 对p进行分类后,再用聚合函数,确保值唯一性,也可以使用其他聚合函数
1 0
- Mysql group by 中行转列
- MySQL Group By 两列
- mysql中行变列
- SQL2005中行转列
- oracle中行转列
- mysql 中group by 和select 列字段数不同
- Oracle中行转列案例
- MySQL中行列转换的SQL技巧
- [转]mysql group by 用法解析(详细)
- mysql中的group by
- mysql group by
- mysql中的group by
- Mysql 的 Group by
- mysql group by优化
- mysql group by 原理
- Mysql值group by
- Mysql group by 详解
- mysql group by用法
- 使用VS最新版本编写cpp程序调用C语言中函数可能报错的原因
- cocoapods 使用 二、实战代码篇章
- Unity3D游戏开发初探—2.初步了解3D模型基础
- jQuery 类的增删用法
- install shield 问题Error 7 -1007
- Mysql group by 中行转列
- PCM 数据 音量改变
- SQL server 2005 windows身份验证登陆失败 错误代码18456
- 关闭WebLaf图形控件的反锯齿功能
- HDU 1003 Max Sum
- 东北大学自动化系灵魂人物
- Andriod之使用极光推送自定义消息打造个性的消息推送效果
- UIVisualEffectView用法 毛玻璃效果
- QT如何支持中文