SQL语句如何统计a时间和b时间有多少个工作日?
答案:3 悬赏:20 手机版
解决时间 2021-03-08 09:19
- 提问者网友:不要迷恋哥
- 2021-03-07 11:57
假设只有周六和周日为节假日
最佳答案
- 五星知识达人网友:青尢
- 2021-03-07 12:41
首先保证,a 与 b 表的时间是 date 或者 datetime 类型:
1、Oracle 写法:
select sum (case when to_char(a.time,'d')-1>=1 and to_char(a.time,'d')-1<=5 then 1
else 0
end)
from tablename a;
2.MSSQL 和 Sybase 写法:
select sum(case when datepart(weekday,a.datetime)-1 >=1 and datepart(weekday,a.datetime)-1<=5 then 1
else 0
end)
from tablename a
1、Oracle 写法:
select sum (case when to_char(a.time,'d')-1>=1 and to_char(a.time,'d')-1<=5 then 1
else 0
end)
from tablename a;
2.MSSQL 和 Sybase 写法:
select sum(case when datepart(weekday,a.datetime)-1 >=1 and datepart(weekday,a.datetime)-1<=5 then 1
else 0
end)
from tablename a
全部回答
- 1楼网友:迷人又混蛋
- 2021-03-07 14:22
declare @a datetime
declare @b datetime
declare @c int
set @a = '2012-07-01'
set @b = GETDATE()
if(DATEPART(WEEKDAY, @a)=1 or DATEPART(WEEKDAY, @a)=7)
set @c = DATEDIFF(DAY, @a, @b)/7 * 5
else
set @c = (DATEDIFF(DAY, @a, @b)/7 * 5) + DATEDIFF(DAY, @a, @b) % 7 - 2
。
- 2楼网友:一袍清酒付
- 2021-03-07 13:32
declare @a datetime
declare @b datetime
declare @c int
set @a = '2012-07-01'
set @b = GETDATE()
if(DATEPART(WEEKDAY, @a)=1 or DATEPART(WEEKDAY, @a)=7)
set @c = DATEDIFF(DAY, @a, @b)/7 * 5
else
set @c = (DATEDIFF(DAY, @a, @b)/7 * 5) + DATEDIFF(DAY, @a, @b) % 7 - 2
select @c
这样就OK
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯