我有 3 个表在一个UNION
. 联合中的每个表都有一个名为 的列timestamp
。我需要将所有时间戳合并在一起,以便它们只显示为一列。
到目前为止,这是我的查询;
SELECT ID, T.T_ID, T.name, T.pic, T.timestamp,
(SELECT COUNT(*) FROM track_plays WHERE T_ID = T.T_ID) AS plays,
(SELECT COUNT(*) FROM track_downloads WHERE T.T_ID) AS downloads,
NULL S_ID, NULL status, NULL timestamp,
NULL G_ID, NULL gig_name, NULL date_time, NULL lineup, NULL price, NULL currency, NULL G_pic, NULL ticket, NULL venue, NULL timestamp
FROM TRACKS T
UNION ALL
SELECT ID, NULL T_ID, NULL name, NULL pic, NULL timestamp, NULL plays, NULL downloads,
S.S_ID, S.status, S.timestamp,
NULL G_ID, NULL gig_name, NULL date_time, NULL lineup, NULL price, NULL currency, NULL G_pic, NULL ticket, NULL venue, NULL timestamp
FROM STATUS S
UNION ALL
SELECT ID, NULL T_ID, NULL name, NULL pic, NULL timestamp, NULL plays, NULL downloads,
NULL S_ID, NULL status, NULL S_ts,
G.G_ID, G.gig_name, G.date_time, G.lineup, G.price, G.currency, G.pic AS G_pic, G.ticket, G.venue, G.timestamp
FROM GIGS G
我会举一些例子,但只是带有ID
时间戳。
这是我需要的
ID timestamp
1 2:00:00
2 5:00:00
3 9:32:00
这就是目前发生的事情
ID T.timestamp S.Timestamp G.timestamp
1 00:00:00 NULL NULL
2 NULL 20:00:00 NULL
3 NULL NULL 08:00:32