(资料图片仅供参考)
select hiredate -5 day as hd_minus_5D, hiredate +5 day as hd_plus_5D, hiredate -5 month as hd_minus_5M, hiredate +5 month as hd_plus_5M, hiredate -5 year as hd_minus_5Y, hiredate +5 year as hd_plus_5Y from emp where deptno = 10select hiredate-5 as hd_minus_5D, hiredate+5 as hd_plus_5D, add_months(hiredate,-5) as hd_minus_5M, add_months(hiredate,5) as hd_plus_5M, add_months(hiredate,-5*12) as hd_minus_5Y, add_months(hiredate,5*12) as hd_plus_5Y from emp where deptno = 10select hiredate - interval "5 day" as hd_minus_5D, hiredate + interval "5 day" as hd_plus_5D, hiredate - interval "5 month" as hd_minus_5M, hiredate + interval "5 month" as hd_plus_5M, hiredate - interval "5 year" as hd_minus_5Y, hiredate + interval "5 year" as hd_plus_5Y from emp where deptno=10select hiredate - interval 5 day as hd_minus_5D, hiredate + interval 5 day as hd_plus_5D, hiredate - interval 5 month as hd_minus_5M, hiredate + interval 5 month as hd_plus_5M, hiredate - interval 5 year as hd_minus_5Y, hiredate + interval 5 year as hd_plus_5Y from emp where deptno=10select date_add(hiredate,interval -5 day) as hd_minus_5D, date_add(hiredate,interval 5 day) as hd_plus_5D, date_add(hiredate,interval -5 month) as hd_minus_5M, date_add(hiredate,interval 5 month) as hd_plus_5M, date_add(hiredate,interval -5 year) as hd_minus_5Y, date_add(hiredate,interval 5 year) as hd_plus_5DY from emp where deptno=10select dateadd(day,-5,hiredate) as hd_minus_5D, dateadd(day,5,hiredate) as hd_plus_5D, dateadd(month,-5,hiredate) as hd_minus_5M, dateadd(month,5,hiredate) as hd_plus_5M, dateadd(year,-5,hiredate) as hd_minus_5Y, dateadd(year,5,hiredate) as hd_plus_5Y from emp where deptno = 10select ward_hd, allen_hd from (select hiredate as ward_hd from emp where ename = "WARD" ) y, (select hiredate as allen_hd from emp where ename = "ALLEN" ) xWARD_HD ALLEN_HD----------- ---------22-FEB-1981 20-FEB-1981select days(ward_hd) - days(allen_hd) from ( select hiredate as ward_hd from emp where ename = "WARD" ) x, ( select hiredate as allen_hd from emp where ename = "ALLEN" ) yselect ward_hd - allen_hd from ( select hiredate as ward_hd from emp where ename = "WARD" ) x, ( select hiredate as allen_hd from emp where ename = "ALLEN" ) yselect datediff(day,allen_hd,ward_hd) from ( select hiredate as ward_hd from emp where ename = "WARD" ) x, ( select hiredate as allen_hd from emp where ename = "ALLEN" ) yselect case when ename = "BLAKE" then hiredate end as blake_hd, case when ename = "JONES" then hiredate end as jones_hd from emp where ename in ( "BLAKE","JONES" )BLAKE_HD JONES_HD----------- ----------- 02-APR-198101-MAY-1981select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" )BLAKE_HD JONES_HD----------- -----------01-MAY-1981 02-APR-1981select x.*, t500.*, jones_hd+t500.id-1 from (select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" ) ) x, t500 where t500.id <= blake_hd-jones_hd+1BLAKE_HD JONES_HD ID JONES_HD+T5----------- ----------- ---------- -----------01-MAY-1981 02-APR-1981 1 02-APR-198101-MAY-1981 02-APR-1981 2 03-APR-198101-MAY-1981 02-APR-1981 3 04-APR-198101-MAY-1981 02-APR-1981 4 05-APR-198101-MAY-1981 02-APR-1981 5 06-APR-198101-MAY-1981 02-APR-1981 6 07-APR-198101-MAY-1981 02-APR-1981 7 08-APR-198101-MAY-1981 02-APR-1981 8 09-APR-198101-MAY-1981 02-APR-1981 9 10-APR-198101-MAY-1981 02-APR-1981 10 11-APR-198101-MAY-1981 02-APR-1981 11 12-APR-198101-MAY-1981 02-APR-1981 12 13-APR-198101-MAY-1981 02-APR-1981 13 14-APR-198101-MAY-1981 02-APR-1981 14 15-APR-198101-MAY-1981 02-APR-1981 15 16-APR-198101-MAY-1981 02-APR-1981 16 17-APR-198101-MAY-1981 02-APR-1981 17 18-APR-198101-MAY-1981 02-APR-1981 18 19-APR-198101-MAY-1981 02-APR-1981 19 20-APR-198101-MAY-1981 02-APR-1981 20 21-APR-198101-MAY-1981 02-APR-1981 21 22-APR-198101-MAY-1981 02-APR-1981 22 23-APR-198101-MAY-1981 02-APR-1981 23 24-APR-198101-MAY-1981 02-APR-1981 24 25-APR-198101-MAY-1981 02-APR-1981 25 26-APR-198101-MAY-1981 02-APR-1981 26 27-APR-198101-MAY-1981 02-APR-1981 27 28-APR-198101-MAY-1981 02-APR-1981 28 29-APR-198101-MAY-1981 02-APR-1981 29 30-APR-198101-MAY-1981 02-APR-1981 30 01-MAY-1981select sum(case when dayname(jones_hd+t500.id day -1 day) in ( "Saturday","Sunday" ) then 0 else 1 end) as days from ( select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" ) ) x, t500 where t500.id <= blake_hd-jones_hd+1select sum(case when to_char(jones_hd+t500.id-1,"DY") in ( "SAT","SUN" ) then 0 else 1 end) as days from ( select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" ) ) x, t500 where t500.id <= blake_hd-jones_hd+1select sum(case when trim(to_char(jones_hd+t500.id-1,"DAY")) in ( "SATURDAY","SUNDAY" ) then 0 else 1 end) as days from ( select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" ) ) x, t500 where t500.id <= blake_hd-jones_hd+1select sum(case when date_format( date_add(jones_hd, interval t500.id-1 DAY),"%a") in ( "Sat","Sun" ) then 0 else 1 end) as days from ( select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" ) ) x, t500 where t500.id <= datediff(blake_hd,jones_hd)+1select sum(case when datename(dw,jones_hd+t500.id-1) in ( "SATURDAY","SUNDAY" ) then 0 else 1 end) as days from ( select max(case when ename = "BLAKE" then hiredate end) as blake_hd, max(case when ename = "JONES" then hiredate end) as jones_hd from emp where ename in ( "BLAKE","JONES" ) ) x, t500 where t500.id <= datediff(day,jones_hd-blake_hd)+1
标签:
Copyright © 2015-2022 西南物业网版权所有 备案号:皖ICP备2022009963号-8 联系邮箱:39 60 29 14 2@qq.com