gpt4 book ai didi

sql - 获取包含系统日期和状态的行

转载 作者:搜寻专家 更新时间:2023-10-30 23:17:59 24 4
gpt4 key购买 nike

>          cycleNO| month |   year|  start date |    close date         |state | prv month  | next mnt 
> 1 4 2012 1/4/2012 30/4/2012 23:59:59 1 3 5
> 1 5 2012 1/5/2012 31/5/2012 23:59:59 0 4 6
> 1 6 2012 1/6/2012 30/6/2012 23:59:59 0 5 7
> 1 7 2012 1/7/2012 31/7/2012 23:59:59 0 6 8
> 2 4 2012 1/4/2012 30/4/2012 23:59:59 1 3 5
> 2 5 2012 1/5/2012 31/5/2012 23:59:59 0 4 6
> 2 6 2012 1/6/2012 30/6/2012 23:59:59 0 5 7
> 2 7 2012 1/7/2012 31/7/2012 23:59:59 0 6 8

我有一个像上面那样的表 (cycle_set) 并且想要获取 (cycleNO,month,year,start date,close date) 的条件是 state =0 和 start-close date 其中包含系统日期也在即时下个月状态 =0。

输出应该是:

cycleNO | month | year | start date | close date 
1 5 2012 1/5/2012 31/5/2012 23:59:59
1 6 2012 1/6/2012 30/6/2012 23:59:59
2 5 2012 1/5/2012 31/5/2012 23:59:59
2 6 2012 1/6/2012 30/6/2012 23:59:59

最佳答案

select cycleNO,month,year,start_date,close_date 
FROM cycle_set
WHERE state=0 and sysdate between start_date and close_date

更新:如果您想同时获得当前和下个月:

select cycleNO, month, year, start_date, close_date 
FROM cycle_set
WHERE state=0
and ( sysdate between start_date and close_date or --current month
sysdate between add_months(start_date,-1) and close_date --next_month
)

关于sql - 获取包含系统日期和状态的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10532457/

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