gpt4 book ai didi

mysql - 合并具有相同列名的两个 MYSQL 表

转载 作者:可可西里 更新时间:2023-11-01 07:49:49 28 4
gpt4 key购买 nike

我有两个表

表一是时间表

id    |   edition    | time   | 
1 | 1 | 9:23am |
2 | 2 | 10:23am|

表二是实际时间

id    | edition  | time    |
1 | 1 | 10:23am |
2 | 2 | 11:23am |

我想要的结果是

Caption    | Edition    | Time    |
Scheduleed | 1 | 9:23am |
actual | 1 | 10:23am |
Scheduleed | 2 | 10:23am |
actual | 2 | 11:23am |

如何在 MySQL 中执行此操作?

最佳答案

SELECT  Caption, Edition, Time
FROM
(
SELECT 'Scheduled' Caption, Edition, time
FROM scheduleTime
UNION ALL
SELECT 'Actual' Caption, Edition, time
FROM scheduleTime
) subquery
ORDER BY Edition, FIELD(Caption, 'Scheduled', 'Actual')

输出

╔═══════════╦═════════╦═════════╗
║ CAPTION ║ EDITION ║ TIME ║
╠═══════════╬═════════╬═════════╣
║ Scheduled ║ 1 ║ 9:23am ║
║ Actual ║ 1 ║ 9:23am ║
║ Scheduled ║ 2 ║ 10:23am ║
║ Actual ║ 2 ║ 10:23am ║
╚═══════════╩═════════╩═════════╝

关于mysql - 合并具有相同列名的两个 MYSQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16117306/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com