专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > MySQL

年月+日(日在列上) 化列为行解决方案

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
年月+日(日在列上) 化列为行
診療年月   |Day_1|Day_2|Day_3|Day_4|Day_5|Day_6|Day_7|Day_8|Day_9|Day_10   ...   |   Day_31   |
      200904 |     0 |     0 |     0 |     0 |     1 |     0 |     0 |     1 |     0 |     0    ...     |     0      |
      200905 |     0 |     1 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0    ...     |     0      |
      200906 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0    ...     |     0      |
      200907 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     1    ...     |     0      |
      200908 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0 |     0    ...     |     1      |
      ...         |...       |...       |...       |...       |...       |...       |...       |...       |...       |...                       |...       |

化列为行 結果以下

  診療年月日
  20090405
  20090408
  20090502
  20090710
  20090831

------解决方案--------------------
估计你的原数据中不会出现 200902 Day_31=1 的情况,则对日期的有效性不做检查了。

SQL code

select concat(诊疗年月,'01') from table1 where Day_1=1 
union all
select concat(诊疗年月,'02') from table1 where Day_2=1 
union all
select concat(诊疗年月,'03') from table1 where Day_3=1 
union all
select concat(诊疗年月,'04') from table1 where Day_4=1 
union all
select concat(诊疗年月,'05') from table1 where Day_5=1 
union all
select concat(诊疗年月,'06') from table1 where Day_6=1 
union all
select concat(诊疗年月,'07') from table1 where Day_7=1 
union all
select concat(诊疗年月,'08') from table1 where Day_8=1 
union all
select concat(诊疗年月,'09') from table1 where Day_9=1 
union all
select concat(诊疗年月,'10') from table1 where Day_10=1 
union all
select concat(诊疗年月,'11') from table1 where Day_11=1 
union all
select concat(诊疗年月,'12') from table1 where Day_12=1 
union all
select concat(诊疗年月,'13') from table1 where Day_13=1 
union all
select concat(诊疗年月,'14') from table1 where Day_14=1 
union all
select concat(诊疗年月,'15') from table1 where Day_15=1 
union all
select concat(诊疗年月,'16') from table1 where Day_16=1 
union all
select concat(诊疗年月,'17') from table1 where Day_17=1 
union all
select concat(诊疗年月,'18') from table1 where Day_18=1 
union all
select concat(诊疗年月,'19') from table1 where Day_19=1 
union all
select concat(诊疗年月,'20') from table1 where Day_20=1 
union all
select concat(诊疗年月,'21') from table1 where Day_21=1 
union all
select concat(诊疗年月,'22') from table1 where Day_22=1 
union all
select concat(诊疗年月,'23') from table1 where Day_23=1 
union all
select concat(诊疗年月,'24') from table1 where Day_24=1 
union all
select concat(诊疗年月,'25') from table1 where Day_25=1 
union all
select concat(诊疗年月,'26') from table1 where Day_26=1 
union all
select concat(诊疗年月,'27') from table1 where Day_27=1 
union all
select concat(诊疗年月,'28') from table1 where Day_28=1 
union all
select concat(诊疗年月,'29') from table1 where Day_29=1 
union all
select concat(诊疗年月,'30') from table1 where Day_30=1 
union all
select concat(诊疗年月,'31') from table1 where Day_31=1
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

  • mysql服务正在启动或终止中请稍后片刻再试一次

    mysql服务正在启动或停止中请稍后片刻再试一次 启动mysql服务总是服务正在启动或停止中请稍后片刻再试一次 的提示怎么办? ...

  • mysql目录以及优化

    mysql索引以及优化 今天看到别人写的一些关于mysql索引的文章,有一些小收获,就以此开启我的随笔记录简单摘了一些重点 转载文章:http...

  • MYSQL查询今日、昨天、7天前、30天、本月数据

    MYSQL查询今天、昨天、7天前、30天、本月数据 今天: SELECT * FROM 表名 WHERE TO_DAYS( 时间字段名) = TO_DAYS(NOW()); 昨天: SEL...

  • MySQL的预加工技术

    MySQL的预处理技术 所谓的预处理技术,最初也是由MySQL提出的一种减轻服务器压力的一种技术! 传统mysql处理流程 1, 在客户端准备sql...

  • 怎么修改Xampp服务器上的mysql密码

    如何修改Xampp服务器上的mysql密码 今天自己在搞php的过程中发现,如果我们使用Xampp服务器自带数据库mysql,就必须先修改mysql的密...

  • MySQL安插emoji手机表情报错解决方案

    MySQL插入emoji手机表情报错解决方案 报错原因: 插入手机表情报错,类似 ...

  • 腾讯云装Mysql总结

    腾讯云装Mysql小结   这几天搞腾讯云服务器装mysql搞蒙了,本来还想这周就上线网站,看来不一定能行了。   总结一下吧   开...

  • MySql概念(2)

    MySql概念(二) 一、Sql规范?   sql是Structured Query Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集,是一...

  • mysql主从复制原理引见

    mysql主从复制原理介绍 mysql主从复制原理 1)在mysql主库上,将改变记录到二进制日志(binary log)中。 2)在mysql从库上,IO线程将mys...

  • 如何查看和修改 MySQL 的最大连接数

    怎么查看和修改 MySQL 的最大连接数 通常,mysql的最大连接数默认是100, 最大可以达到16384。 1、查看最大连接数: show varia...

热门推荐: