下面是我蒐集的一些精妙的sql語句
說明:複製表(只複製結構,源表名:a 新錶名:b)
select * into b from a where 1<>1
說明:拷貝表(拷貝資料,源表名:a 目標表名:b)
insert into b(a, b, c) select d,e,f from b;
select a.title,a.username,b.adddate
from table a,(
select max(adddate) adddate
from table
where table.title=a.title
) b
說明:外連線查詢(表名1:a 表名2:b)
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 * from 日程安排 where datediff('minute',f開始時間,getdate())>5
說明:兩張關聯表,刪除主表中已經在副表中沒有的資訊
delete from info where not exists ( select * from infobz where info.infid=infobz.infid )
說明:四表聯查問題:
select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....
說明:得到表中最小的未使用的id號
select (case when exists(select * from handle b where b.handleid = 1) then min(handleid) + 1 else 1 end) as handleid
from handle
where not handleid in (select a.handleid - 1 from handle a)
coalesce
返回其引數中第乙個非空表示式。
語法
coalesce ( expression [ ,...n ] )
一些很精妙的sql
1 說明 複製表 只複製結構,源表名 a 新錶名 b access可用 法一 select into b from a where 1 1 法二 select top 0 into b from a 2 說明 拷貝表 拷貝資料,源表名 a 目標表名 b access可用 insert into b ...
精妙的SQL語句2
1.說明 複製表 只複製結構,源表名 a 新錶名 b sql select into b from a where 1 1 2.說明 拷貝表 拷貝資料,源表名 a 目標表名 b sql insert into b a,b,c select d,e,f from a sql select a.titl...
一些sql語句
一。在oracle中建表,怎麼實現id自動編號 1 建表 create table code test id int,name varchar2 20 2.建立序列 create sequence s country id increment by 1 start with 1 maxvalue 9...