SQL:数据库中的某个时间,判断这个时间属于3个时间段中的哪一个时间段?

2025-03-11 15:37:43
推荐回答(1个)
回答1:

某个时间:date

时间段1:date1~date2

时间段2:date3~date4

时间段3:date5~date6


case

when date between date1 and date2 then '时间段'1'

when date between date3 and date4 then '时间段'2'

when date between date5 and date6 then '时间段'3'

end '时间段'