行转列,行合并,日期转星期问题
时间:2011-12-02
来源:互联网
表一
id date begin end
1 2011-12-2 09:30 10:00
1 2011-12-2 10:30 11:00
1 2011-12-3 09:30 10:00
2 2011-12-2 09:30 10:00
2 2011-12-2 10:30 11:00
2 2011-12-4 09:30 10:00
3 2011-12-2 09:30 10:00
3 2011-12-2 10:30 11:00
3 2011-12-4 09:30 10:00
表二
id 星期五 星期六 星期天
-----------------------------------------------------
1 09:30-10:00; 09:30-10:00; ( )
10:30-11:00;
-----------------------------------------------------
2 09:30-10:00; ( ) 09:30-10:00;
10:30-11:00;
-----------------------------------------------------
3 09:30-10:00; ( ) 09:30-10:00;
10:30-11:00;
-----------------------------------------------------
表一转表二 如何用sql语句实现.
id date begin end
1 2011-12-2 09:30 10:00
1 2011-12-2 10:30 11:00
1 2011-12-3 09:30 10:00
2 2011-12-2 09:30 10:00
2 2011-12-2 10:30 11:00
2 2011-12-4 09:30 10:00
3 2011-12-2 09:30 10:00
3 2011-12-2 10:30 11:00
3 2011-12-4 09:30 10:00
表二
id 星期五 星期六 星期天
-----------------------------------------------------
1 09:30-10:00; 09:30-10:00; ( )
10:30-11:00;
-----------------------------------------------------
2 09:30-10:00; ( ) 09:30-10:00;
10:30-11:00;
-----------------------------------------------------
3 09:30-10:00; ( ) 09:30-10:00;
10:30-11:00;
-----------------------------------------------------
表一转表二 如何用sql语句实现.
作者: mojo_mask 发布时间: 2011-12-02
SQL code
-----
1 09:30-10:00,10:30-11:00 09:30-10:00
2 09:30-10:00,10:30-11:00 09:30-10:00
3 09:30-10:00,10:30-11:00 09:30-10:00
with t as ( select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all select 1 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from dual union all select 1 id ,date '2011-12-3' ddate, '09:30' begin, '10:00' end from dual union all select 2 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all select 2 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from dual union all select 2 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from dual union all select 3 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all select 3 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from dual union all select 3 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from dual ) select id ,wm_concat(a),wm_concat(b),wm_concat(c) from ( select id,decode(to_char(ddate,'dy'),'星期五',(begin||'-'||end)) a, decode(to_char(ddate,'dy'),'星期六',(begin||'-'||end)) b, decode(to_char(ddate,'dy'),'星期日',(begin||'-'||end)) c from t ) tt group by tt.id
-----
1 09:30-10:00,10:30-11:00 09:30-10:00
2 09:30-10:00,10:30-11:00 09:30-10:00
3 09:30-10:00,10:30-11:00 09:30-10:00
作者: dws2004 发布时间: 2011-12-02
我晕,粘贴结果怎么这样;额
SQL code
SQL code
1 09:30-10:00,10:30-11:00 09:30-10:00 2 09:30-10:00,10:30-11:00 09:30-10:00 3 09:30-10:00,10:30-11:00 09:30-10:00
作者: dws2004 发布时间: 2011-12-02
引用 1 楼 dws2004 的回复:
SQL code
with t as (
select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all
select 1 id ,date '2011-12-2' ddate, '10:30' ……
SQL code
with t as (
select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all
select 1 id ,date '2011-12-2' ddate, '10:30' ……
那不是有几条数据那我就要写几条数据
作者: mojo_mask 发布时间: 2011-12-02
SQL code
这些语句的目的是为了建立测试数据,你有实际的表,不用写前面这些。
直接从实际表中的查询即可。
with t as ( select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all select 1 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from dual union all select 1 id ,date '2011-12-3' ddate, '09:30' begin, '10:00' end from dual union all select 2 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all select 2 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from dual union all select 2 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from dual union all select 3 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all select 3 id ,date '2011-12-2' ddate, '10:30' begin, '11:00' end from dual union all select 3 id ,date '2011-12-4' ddate, '09:30' begin, '10:00' end from dual )
这些语句的目的是为了建立测试数据,你有实际的表,不用写前面这些。
直接从实际表中的查询即可。
作者: LuiseRADL 发布时间: 2011-12-02
引用 4 楼 luiseradl 的回复:
SQL code
with t as (
select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all
select 1 id ,date '2011-12-2' ddate, '10:30'……
SQL code
with t as (
select 1 id ,date '2011-12-2' ddate, '09:30' begin, '10:00' end from dual union all
select 1 id ,date '2011-12-2' ddate, '10:30'……
3Q,感谢
作者: mojo_mask 发布时间: 2011-12-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28