gpt4 book ai didi

MySQL 将 2 个查询连接到同一个表

转载 作者:行者123 更新时间:2023-11-30 21:37:48 25 4
gpt4 key购买 nike

您好,我正在尝试将以下查询加入一个表

第一个查询是

SET @row_number = 0;

SELECT
(@row_number:=@row_number + 1) AS Batch, t_stamp as Date, Total
FROM
food
ORDER BY t_stamp ASC
LIMIT 45

第二个查询是

SET @row_number = 45;
SELECT
(@row_number:=@row_number + 1) AS Batch, t_stamp as Date, Total
FROM
food
ORDER BY t_stamp ASC
LIMIT 50, 45

我想要实现的是如下表

Batch |  Date  |  Total  |     Batch  |  Date     |  Total
1 9.00am 10 46 12.30pm 10
2 10.00am 10 47 1.00pm 10
- -
45 12.00pm 10 90 2.00pm 10

任何建议都会很棒。谢谢

最佳答案

您可以尝试使用 UNION ALL 合并两个数据集

SET @row_number = 0;
SET @row_number1 = 45;

select * from
(SELECT
(@row_number:=@row_number + 1) AS Batch, t_stamp as Date, Total
FROM
food
ORDER BY t_stamp ASC
LIMIT 45
)A
union all

select * from
(
SELECT
(@row_number1:=@row_number1 + 1) AS Batch, t_stamp as Date, Total
FROM
food
ORDER BY t_stamp ASC
LIMIT 50, 45
)
B

关于MySQL 将 2 个查询连接到同一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53076526/

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