幾條經典的SQL語句

2022-05-07 15:24:11 字數 1380 閱讀 1355

sql: select * into b from a where 1<>1   

說明:拷貝表(拷貝資料,源表名:a 目標表名:b)

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

sql: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table b where table.title=a.title)   

說明:外連線查詢(表名1:a 表名2:b)

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

軟體開發網

軟體開發網

sql: select * from 日程安排 where datediff('minute',f開始時間,getdate())>5   

說明:兩張關聯表,刪除主表中已經在副表中沒有的資訊 軟體開發網

sql:

delete from info where not exists ( select * from infobz where info.infid=infobz.infid )   

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   

sql:

select * from studentinfo where not exists(select * from student where studentinfo.id=student.id) and 系名稱='"&strdepartmentname&"' and 專業名稱='"&strprofessionname&"' order by 性別,生源地,高考總成績

幾條常用的sql查詢語句

select from table where type 1 以上是一條最簡單的sql條件查詢語句,那我們如果有2個type需要同時查詢呢?我們可以這樣寫 select from table where type 1 or type 2 如果,我們查出的結果是多個,且需要排序呢?關鍵字 order ...

經典的SQL語句

說明 複製表 只複製結構,源表名 a 新錶名 b b不存在 sql select into b from a where 1 1 說明 拷貝表 拷貝資料,源表名 a 目標表名 b b存在 sql insert into b a,b,c select d,e,f from b sql select a...

sql經典語句

說明 複製表 只複製結構,源表名 a 新錶名 b access可用 方法一 select into b from a where 1 1 方法二 select top 0 into b from a 注意 複製的新錶中的所有欄位都將沒有預設值,即使源表中有設預設值 說明 一條sql 語句搞定資料庫分...