gpt4 book ai didi

mysql - Mysql查询中dayname等于星期六或星期日如何跳过该列

转载 作者:行者123 更新时间:2023-11-29 04:45:04 24 4
gpt4 key购买 nike

我只想显示日期,假设如果我选择一个日期 2013 年 12 月 1 日,那么我们需要显示接下来的 7 天

2013-12-01 2013-12-02 2013-12-03 2013-12-04 2013-12-05 2013-12-06 2013-12-07

这里是mysql查询

select
cast('2013-12-01' as date) AS `1`,
(cast('2013-12-01' as date) + interval 1 day) AS `2`,
(cast('2013-12-01' as date) + interval 2 day) AS `3`,
(cast('2013-12-01' as date) + interval 3 day) AS `4`,
(cast('2013-12-01' as date) + interval 4 day) AS `5`,
(cast('2013-12-01' as date) + interval 5 day) AS `6`,
(cast('2013-12-01' as date) + interval 6 day) AS `7`,
(cast('2013-12-01' as date) + interval 7 day) AS `8`,
(cast('2013-12-01' as date) + interval 8 day) AS `9`,
(cast('2013-12-01' as date) + interval 9 day) AS `10`,
(cast('2013-12-01' as date) + interval 10 day) AS `11`

它给了我直到 2013-02-11 的所有时间,但我想跳过那些 dayname = "Saturday"或 "Sunday"的列,我该如何解决这个问题。我尝试了很多但都失败了。希望你能帮助我。

提前致谢。

最佳答案

像这样:

select GROUP_CONCAT(dt)
FROM
(
select
(cast('2013-12-01' as date) + interval t.n day) dt
FROM
(
select 0 as n union all
select 1 as n union all
select 2 as n union all
select 3 as n union all
select 4 as n union all
select 5 as n union all
select 6 as n union all
select 7 as n union all
select 8 as n union all
select 9 as n union all
select 10 as n union all
select 11 as n union all
select 12 as n union all
select 13 as n) t
WHERE WEEKDAY((cast('2013-12-01' as date) + interval t.n day)) not in (5,6)
ORDER BY dt
LIMIT 7
) t1

SQLFiddle demo

关于mysql - Mysql查询中dayname等于星期六或星期日如何跳过该列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20423327/

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