![](/img/trans.png)
[英]SQL Server from two dates get working(excluding saturdays and sundays) days group by month and year
[英]how to subtract the Sundays from no of days in a month
如何找出一个月中的星期日?
请帮助我。
星期日的数量:当前月份为4,我需要从一个月的天中减去这些计数
::一个月中的天数-周日
如果我将日期从传递到之间,则需要获取该时段的周日计数。
非常感谢您的帮助。
Sunitha ..
尝试这个:
select to_char(last_day(sysdate),'dd') -
((next_day(last_day(trunc(sysdate)),'sunday')-7
-next_day(trunc(sysdate,'mm')-1,'sunday'))/7+1) as result
from dual
对于期间之间的计数日期,您可以执行以下操作:
SELECT (next_day(TRUNC(TO_DATE('28/09/2014','DD/MM/YYYY')),'sunday') -
next_day((trunc(TO_DATE('13/09/2014','DD/MM/YYYY'))),'sunday')-7)/7+1 AS RESULT
FROM DUAL
如果有从和到日期,则应首先使用层次查询生成它们之间的所有日期。 然后仅从中过滤星期日。
select count(1)
from (
select start_date + level - 1 as dates
from dual
connect by start_date + level - 1 <= end_date
)
where to_char(dates,'fmday') = 'sunday';
如果要计算当前月份的非星期日数量,请找到该月份的第一天和最后一天,并按照上述相同的步骤进行操作。
select count(1)
from (
select start_date + level - 1 as dates
from (
select trunc(sysdate,'month') as start_date,
last_day(sysdate) as end_date
from dual
)
connect by start_date + level - 1 <= end_date
)
where to_char(dates,'fmday') != 'sunday';
SELECT (
(
TO_CHAR(next_day(last_day(TRUNC(sysdate))-7,'SUN'),'DD')-
TO_CHAR(next_day(last_day(TRUNC(sysdate-30)),'SUN'),'DD')
)/7
)+1
FROM dual;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.