gpt4 book ai didi

mysql - 多个查询合并为一个?

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:52 25 4
gpt4 key购买 nike

如何将其放入一个查询中?

例如:

SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`)  = '2012' limit 20
SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`) = '2013' limit 20
SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`) = '2014' limit 20
SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`) = '2015' limit 20

SELECT * FROM `result` WHERE status = 'new' AND DAY(`end_date`) = '1' limit 20
SELECT * FROM `result` WHERE status = 'new' AND DAY(`end_date`) = '2' limit 20
... and to 31

and same for the Month Jan to Dec

基本显示每天、每月、每年20条记录。

最佳答案

您可以使用 UNION 合并结果集这样:

SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`)  = '2012' limit 20
UNION
SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`) = '2013' limit 20
UNION
SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`) = '2014' limit 20
UNION
SELECT * FROM `result` WHERE status = 'new' AND YEAR(`end_date`) = '2015' limit 20
UNION
SELECT * FROM `result` WHERE status = 'new' AND DAY(`end_date`) = '1' limit 20
UNION
SELECT * FROM `result` WHERE status = 'new' AND DAY(`end_date`) = '2' limit 20
ORDER BY submit_date DESC

关于mysql - 多个查询合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11808100/

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