数据库中用sql语句进行行列转换

来源:互联网 发布:centos安装nodejs 编辑:程序博客网 时间:2024/06/05 18:07
1、排重
用到排重的sql语句

select distinct(region) from T_ORGAN where AAID = '0010' and group_type = 0 and connect = 1 and mid is not null and Deleted = 0



2、行转列/列转行


Pivot是行转列

Unpivot是列转行



由第二幅图转换成第一幅图,只需要用到pivot

select  星期一 , 星期二,   星期三,  星期四,  星期五,   星期六 , 星期日from test  pivot (sum(income) for week   in(星期一 , 星期二,   星期三,  星期四,  星期五,   星期六 , 星期日))  as tt



1 0
原创粉丝点击