我使用的mySql表如下所示:
ID mondend |MondStart |TuesEnd |TuesStrt |wedsEnd |wednStrt
120| 06:00:00 | 22:00:00 |06:00:00 |22:00:00 |06:00:00 |22:00:00
122| 06:00:00 | 22:00:00 |06:00:00 |22:00:00 |06:00:00 |22:00:00
是否有可能通过查询使表格看起来像这样?:
120| monday | 22:00:00 |06:00:00 |
| tuesday | 22:00:00 |06:00:00 |
| tuesday | 22:00:00 |06:00:00 |
122|monday | 22:00:00 |06:00:00 |
| tuesday | 22:00:00 |06:00:00 |
| tuesday | 22:00:00 |06:00:00 |
答案 0 :(得分:0)
一种解决方案是使用UNION ALL查询:
SELECT ID, 'monday' AS week_day, MondStart AS day_start, TuesEnd day_end
FROM tablename
UNION ALL
SELECT ID, 'tuesday' AS week_day, TuesStrt AS day_start, WedEnd day_end
FROM tablename
UNION ALL
...etc...
如果你想要一个表而不是一个查询,你可以使用:
CREATE TABLE final_table AS
...the select query above...