select coalesce(total.fab, preborrow.fab,'-') fab,nvl(total.qty,0) total,nvl(borrow.qty,0) borrow,nvl(idle.qty,0) idle,nvl(overdue.qty,0)
overdue,nvl(preborrow.qty,0) preborrow from
(select fab,count(*) qty from mpb_camera_r where fab is not null and is_active='y' and camera_type=camera group by fab ) total
left join (select fab,count(*) qty from mpb_camera_r where fab is not null and is_active='y' and camera_type=camera and status='using' group by fab) borrow on total.fab=borrow.fab left join (select fab,count(*) qty from mpb_camera_r where fab is not null and is_active='y' and camera_type=camera and status='idle' group by fab) idle on total.fab=idle.fab
left join (select fab,count(*) qty from mpb_camera_r where fab is not null and is_active='y' and camera_type=camera and status='using' and sysdate > status_update_time+ " + alerttime.tostring() + " /24 group by fab) overdue on total.fab=overdue.fab " +
"full join (select fab,count(*) qty from mpb_preborrow_r where fab is not null and status='pre' and equipment_type=camera group by fab) preborrow on total.fab=preborrow.fab ";
1:select字句的《目標列表示式》 不僅可以是表中的屬性列也可也是表示式
如: select 2015—age from student 得到學生出生年份
使用者可以指定別名來改變查詢結果的列標題 這對於含算術表示式,常量,函式名的目標列表示式尤為重要
select sname name,'year of birth' brith,2015-age brithday,lower(sdept) department from student;
2:函式coalesce :
3:nvl:
4:left join
5:full join
6:count(*)
oracle 語句轉mysql語句
oracle to date 06 08 2019 16 20 50 dd mm yyyy hh24 mi ss mysql str to date 06 08 2019 16 20 50 d m y h i s mysql 類似to char to date 函式 mysql日期和字元相互轉換方法...
oracle語句相關
巢狀查詢 定義 1 指在乙個外層查詢中包含有另乙個內層查詢。其中外層查詢稱為主查詢,內層查詢稱為子查詢。2 sql 允許多層巢狀,由內而外地進行分析,子查詢的結果作為主查詢的查詢條件 3 子查詢中一般不使用 order by 子句,只能對最終查詢結果進行排序 子查詢 sub query where ...
Oracle基礎語句
1 連線資料庫 connect uuu ooo connect sys ok as sysdba 2 建立表空間 create tablespace stu 表空間名 datafile e stu.dbf size 100m autoextend on next 5m maxsize 500m 3 ...