6

私は2つのテーブルを持っています

テーブル 1 はスケジュールタイムです

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

表 2 は実際の時間です

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 でこれを行うにはどうすればよいですか?

4

4 に答える 4

10
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 ║
╚═══════════╩═════════╩═════════╝
于 2013-04-20T06:18:07.547 に答える
0
select * from
(select 'Scheduleed' as Caption, Edition as Edition, Time as Time from scheduletime

union all

select 'actual' as Caption, Edition as Edition, Time as Time from actualtime) as a

order by Edition

多分これはあなたを助けるでしょう

于 2013-04-20T06:15:52.897 に答える
0

これを試して:

SELECT 
    'Scheduleed' AS Caption, 
    Edition, 
    time 
FROM scheduletime
UNION ALL
SELECT 
    'actual' AS Caption, 
    Edition, 
    time 
FROM actualtime
ORDER BY Edition, Caption DESC

出力:

|    CAPTION | EDITION |    TIME |
----------------------------------
| Scheduleed |       1 |  9:23am |
|     actual |       1 | 10:23am |
| Scheduleed |       2 | 10:23am |
|     actual |       2 | 11:23am |

このSQLFiddleを参照してください

于 2013-04-20T06:17:52.667 に答える
0

使用できます:-

select * from(
select 'Scheduleed' as Caption ,edition,time from scheduletime

union all

select 'actual' as Caption,edition,time from actualtime
)x 
于 2013-04-20T06:38:17.483 に答える