mysql行转列(日期)
CREATE TABLE `tet` (
`id` int(10) not NULL AUTO_INCREMENT,
`name` varchar(40) COLLATE utf8mb4_bin not NULL default '',
table_size decimal(15,2) NOT NULL DEFAULT '0.00',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB AUTO_INCREMENT=0;
mysql> select * from tet order by create_time;
+----+------------+------------+---------------------+
| id | name | table_size | create_time |
+----+------------+------------+---------------------+
| 1 | order_item | 34.00 | 2019-03-01 13:00:04 |
| 3 | order_item | 60.00 | 2019-03-15 13:00:04 |
| 2 | order_item | 54.00 | 2019-03-30 13:00:04 |
+----+------------+------------+---------------------+
想转换为:
name 2019-03-01 13:00:04 2019-03-15 13:00:04 2019-03-30 13:00:04
order_item 34.00 60.00 54.00
请教下sql如何写?
`id` int(10) not NULL AUTO_INCREMENT,
`name` varchar(40) COLLATE utf8mb4_bin not NULL default '',
table_size decimal(15,2) NOT NULL DEFAULT '0.00',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB AUTO_INCREMENT=0;
mysql> select * from tet order by create_time;
+----+------------+------------+---------------------+
| id | name | table_size | create_time |
+----+------------+------------+---------------------+
| 1 | order_item | 34.00 | 2019-03-01 13:00:04 |
| 3 | order_item | 60.00 | 2019-03-15 13:00:04 |
| 2 | order_item | 54.00 | 2019-03-30 13:00:04 |
+----+------------+------------+---------------------+
想转换为:
name 2019-03-01 13:00:04 2019-03-15 13:00:04 2019-03-30 13:00:04
order_item 34.00 60.00 54.00
请教下sql如何写?
...全文
相关推荐
mysql复杂动态行转列解决方案
NULL 博文链接:https://pmandy-163-com.iteye.com/blog/789326
mysql动态行转列
mysql动态行转列代码,很不错的例子。
Mysql 行转列 实现中派商家月额统计
NULL 博文链接:https://wangming2012.iteye.com/blog/1942144
Oracle与Mysql差异说明.doc
Oracle数据库与Mysql数据库之间的差异
mysql列转行以及年月分组实例
下面小编就为大家带来一篇mysql列转行以及年月分组实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧


