设为首页 加入收藏

TOP

oracle decode函数竖表转横表
2014-11-24 02:37:56 来源: 作者: 【 】 浏览:1
Tags:oracle decode 函数

1.原始数据列:
手机号码,日期,数量
2.decode查询结果列:
手机号码,10月1日数量总和,10月2日数量总和。。。10月7日数量总和
select distinct recommender,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-01', 1, 0)) num,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-02', 1, 0)) num,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-03', 1, 0)) num,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-04', 1, 0)) num,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-05', 1, 0)) num,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-06', 1, 0)) num,
sum(decode(to_char(handel_date, 'yyyy-mm-dd'), '2012-10-07', 1, 0)) num
from rurality_recommenddg t www.2cto.com
where t.status = '3'
and t.handel_date > to_date('2012-10-01', 'yyyy-mm-dd')
and t.handel_date < to_date('2012-10-08', 'yyyy-mm-dd')
group by recommender;
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORA-12514监听错误解决 下一篇ORA-12514及ORA-28547错误解决

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)