MYSQL数据的行列置换
2008-12-24 11:17
246 查看
脚本:
select stat_date,class_id,
case when origin ='ad' then sum(pv) else 0 end as m1,
case when origin<>'ad' then sum(pv) else 0 end as m2
from t_stat_goods_page_by_hour
where
datediff(stat_date,'2008-12-17')>=0 and datediff(stat_date,'2008-12-23')<=0
and page_type='m1'
group by stat_date,origin,class_id
注意的是 case when 中的区分词 (如例子脚本中的 origin字段必须在 group by 中,否则会出现某列为0的情况)
select stat_date,class_id,
case when origin ='ad' then sum(pv) else 0 end as m1,
case when origin<>'ad' then sum(pv) else 0 end as m2
from t_stat_goods_page_by_hour
where
datediff(stat_date,'2008-12-17')>=0 and datediff(stat_date,'2008-12-23')<=0
and page_type='m1'
group by stat_date,origin,class_id
注意的是 case when 中的区分词 (如例子脚本中的 origin字段必须在 group by 中,否则会出现某列为0的情况)
相关文章推荐
- MYSQL数据的行列置换
- MYSQL 数据行列交换 存储过程实现
- [MySQL] 行列转换变化各种方法实现总结(行变列报表统计、列变行数据记录统计等)
- [MySQL] 行列转换变化各种方法实现总结(行变列报表统计、列变行数据记录统计等
- MySQL数据表约束筛选v.s.行列运算
- MySQL] 行列转换变化各种方法实现总结(行变列报表统计、列变行数据记录统计等)
- 数据库表行列转置的实现_Mysql
- mysql表数据行列转换方法
- mySql 数据库表行列转换
- 行列置换数据展现方式(多维数据集方案)
- 第一篇博文之mysql表表连接查询和行列置换问题
- [MySQL] 行列转换变化各种方法实现总结(行变列报表统计、列变行数据记录统计等)
- MySql表数据行列转换
- mysql 行列互换,列列互换数据,数组列转多行数据
- 帮助类解决日期时间问题(包含从Mysql中查出来的数据后面多了个0的问题,以友好的方式显示时间的问题)
- mysql:insert插入数据过慢如何解决,设置innodb_flush_log_at_trx_commit为0就能解决
- 基于CentOS的MySQL学习补充四--使用Shell批量从CSV文件里插入数据到数据表
- mysql 数据的批量导入
- 懒人懒办法:把Excel数据导入到MySQL中