oracle sql查詢日曆

2021-05-23 21:36:13 字數 844 閱讀 6882

查詢當前時間所在月份的日曆

select sum(d1) 星期日,

sum(d2) 星期一,

sum(d3) 星期二,

sum(d4) 星期三,

sum(d5) 星期四,

sum(d6) 星期五,

sum(d7) 星期六

from (select decode(d, 1, l) d1,

decode(d, 2, l) d2,

decode(d, 3, l) d3,

decode(d, 4, l) d4,

decode(d, 5, l) d5,

decode(d, 6, l) d6,

decode(d, 7, l) d7,

case

when d >= fd then

row_number() over(partition by d order by l) - 1

else

row_number() over(partition by d order by l)

end ro

from (select level l,--日期

to_char(add_months(last_day(sysdate), -1) + level, 'd') d,--星期幾

to_char(add_months(last_day(sysdate), -1) + 1, 'd') fd --第一天星期幾

from dual

connect by level <= to_char(last_day(sysdate), 'dd')))

group by ro

order by nvl(sum(d1) ,0)

oracleSQL基本查詢

create table dept deptno number primary key,dname nvarchar2 50 log nvarchar2 50 select from dept for update create table enp empno number primary key,...

ORACLE SQL多表查詢

使用連線在多個表中查詢資料 在 where 子句中寫入連線條件 在表中有相同列時,在列名之前加上表名字首 1 等值連線 2 非等值連線 in 例 查詢每個員工的 last name 和 grade level 在 job grades 表中 非等值連線 select last name,salary...

ORACLE SQL 多變查詢

迪卡爾集 笛卡爾集會在下面條件下產生 省略連線條件 連線條件無效 所有表中的所有行互相連線 為了避免笛卡爾集,可以在 where 加入有效的連線條件。使用連線多表連線查詢 在 where字句寫加入連線條件 在表中有相同列事,在表名之前加上表名字首 等價連線 select e.department i...