pony

抄袭是一种美德

MYSQL数据的行列置换

脚本:
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的情况)

posted on 2008-12-24 11:17  马森  阅读(289)  评论(0编辑  收藏  举报

导航