我正在尝试将两个记录合并为一个,我看到了一些类似的问题,但这些似乎不是数据库中的特定记录
SELECT Summary1 as a, Summary2 as b, Summary3 as c, DateUpdated as d
FROM tbl_EC where id=1
SELECT Summary1 as e, Summary2 as f, Summary3 as g, DateUpdated as h
FROM tbl_EC where id=2
答案 0 :(得分:1)
自我加入:
SELECT t1.Summary1 as a, t1.Summary2 as b, t1.Summary3 as c, t1.DateUpdated as d,
t2.Summary1 as e, t2.Summary2 as f, t2.Summary3 as g, t2.DateUpdated as h
FROM tbl_EC t1
JOIN tbl_EC t2 ON t1.id + 1 = t2.id
WHERE t1.ID = 1
如果可能缺少任何ID,或许您想切换到FULL OUTER JOIN
?
SELECT t1.Summary1 as a, t1.Summary2 as b, t1.Summary3 as c, t1.DateUpdated as d,
t2.Summary1 as e, t2.Summary2 as f, t2.Summary3 as g, t2.DateUpdated as h
FROM tbl_EC t1
FULL OUTER JOIN tbl_EC t2 ON t1.id + 1 = t2.id
and (t1.id % 2 = 1 or t2.id % 2 = 0)