答案 0 :(得分:1)
在MySQL中做这件事太可怕了,最好还是用一种应用程序语言来做。
您可以执行以下操作,但是它缺乏任何可扩展性:
0
答案 1 :(得分:0)
请尝试下面的查询,它将动态地将行分解为没有任何参数的列,只需将“ Time”替换为您的列名即可。
SELECT b.*, c.* from
(SELECT CEILING(COUNT(id) / 2) as totalId from test) as a JOIN
(SELECT id as id1, Time as column1 FROM test) as b LEFT JOIN
(SELECT id as id2, Time as column2 FROM test) as c
ON b.id1 = c.id2-a.totalId
WHERE b.id1 < a.totalId+1
您也可以将*替换为列名:
SELECT b.column1, c.column2 from
(SELECT CEILING(COUNT(id) / 2) as totalId from test) as a JOIN
(SELECT id as id1, Time as column1 FROM test) as b LEFT JOIN
(SELECT id as id2, Time as column2 FROM test) as c
ON b.id1 = c.id2-a.totalId
WHERE b.id1 < a.totalId+1