功能強大的SQL語句

2021-05-22 14:05:36 字數 3115 閱讀 3046

1. 複製表結構

sql**

1. select * into b from a where 1=0;   

select * into b from a where 1=0;

2.複製表記錄 複製某些字段

sql**

1. insert into b(a, b, c) select d, e, f from a;   

insert into b(a, b, c) select d, e, f from a;

複製整個表記錄

sql**

1. insert into b select * from a;   

insert into b select * from a;

3.外連線查詢

sql**

1. select a.a, a.b, a.c, b.c, b.d, b.f from a left out join b on a.a = b.c;    

select a.a, a.b, a.c, b.c, b.d, b.f from a left out join b on a.a = b.c;  

4.取特定時間內的資料

sql**

1. select * from a where datediff("minute", 開始時間字段, getdate())>時間差    

select * from a where datediff("minute", 開始時間字段, getdate())>時間差  

5.兩張關聯表,刪除主表中已經在副表中沒有的資訊

sql**

1. delete from a where not exists(select id from b where a.infid=b.infid );  

delete from a where not exists(select id from b where a.infid=b.infid );

6. 複雜的多級條件查詢

sql**

1. select a.num, a.name, b.upd_date, b.prev_upd_date   

2.      from table1,(select x.num, x.upd_date, y.upd_date prev_upd_date   

3.                   from (select num, upd_date, inbound_qty, stock_onhand   

4.                         from table2   

5.                         where to_char(upd_date,』』yyyy/mm』』) =   

6.                               to_char(sysdate, 』』yyyy/mm』』)) x,   

7.                        (select num, upd_date, stock_onhand   

8.                         from table2   

9.                         where to_char(upd_date,』』yyyy/mm』』) =   

10.                               to_char(to_date(to_char(sysdate, 』』yyyy/mm』』)   

11.                               || 』』/01』』,』』yyyy/mm/dd』』) - 1, 』』yyyy/mm』』) ) y,   

12.                    where x.num = y.num (+)and x.inbound_qty   

13.                                  + nvl(y.stock_onhand,0) <> x.stock_onhand ) b   

14.                    where a.num = b.num;   

15.    

select a.num, a.name, b.upd_date, b.prev_upd_date

from table1,(select x.num, x.upd_date, y.upd_date prev_upd_date

from (select num, upd_date, inbound_qty, stock_onhand

from table2

where to_char(upd_date,』』yyyy/mm』』) =

to_char(sysdate, 』』yyyy/mm』』)) x,

(select num, upd_date, stock_onhand

from table2

where to_char(upd_date,』』yyyy/mm』』) =

to_char(to_date(to_char(sysdate, 』』yyyy/mm』』)

|| 』』/01』』,』』yyyy/mm/dd』』) - 1, 』』yyyy/mm』』) ) y,

where x.num = y.num (+)and x.inbound_qty

+ nvl(y.stock_onhand,0) <> x.stock_onhand ) b

where a.num = b.num; 

7.兩個表之間的關聯資料篩選

sql**

1. select * from a   

2.      where not exists(select id from b where a.id=b.id)   

3.            and a.a="*"  

4.            and a.b="*"  

5.      order by a.c,a.d,a.e;  

select * from a

where not exists(select id from b where a.id=b.id)

and a.a="*"

and a.b="*"

order by a.c,a.d,a.e;

sql**

1.

功能強大的SQL語句

1.複製表結構 select into b from a where 1 0 2.複製表記錄 複製某些字段 insert into b a,b,c select d,e,f from a 複製整個表記錄 insert into b select from a 3.外連線查詢 select a.a,a...

功能強大的KSnapshot

ksnapshot是kde整合桌面環境自帶的截圖工具,不過在gnome整合桌面環境下也可以安裝和使用它。我們可以通過新立得軟體包管理器或使用apt get命令來安裝它。假設使用命令列方式來安裝,開啟乙個gnome終端視窗,在終端視窗中輸入如下命令 sudo apt get install ksnap...

功能強大的sscanf 函式

int sscanf const char src,const char format,int scanf const char format,這兩個函式很相似,只是第乙個函式以src作為輸入,而第二個函式以標準輸入stdin讀取輸入 format 是格式控制字串,它包含控制字元 如 d,i,s等 ...