|
|
本頁的SQL例句全部懂了,你的數(shù)據(jù)庫開發(fā)所需知識(shí)就夠用了 |
|
來源:yocin 時(shí)間:2012-2-17 14:20:01 欄目:技術(shù)支持 點(diǎn)擊率:4815 |
--======子查詢============ --在一個(gè)SQL語句中鑲?cè)肓硪粋(gè)SQL語句教鑲套查詢,而被鑲?cè)氲倪@個(gè)SQL語句就被江湖人稱子查詢。是處理多表操作的附加方法 --子查詢也稱內(nèi)部查詢,而包含子查詢的Select語句被誠為外部查詢,子查詢自身可以包括一個(gè)或者多個(gè)子查詢,也可以鑲套任意數(shù)量的子查詢
--使用in的子查詢 select * from studio where cl_id in (select cl_id from class where cl_id>2) --使用 not in select * from studio where cl_id not in (select cl_id from class where cl_id>2)
--使用比較運(yùn)算符的子查詢 -- any 表示子查詢中任意的值 all 表示子查詢中的每個(gè)值 --使用any select * from class where cl_id>any(select cl_id from studio where st_age>30) --使用all select * from class where cl_id>all(select cl_id from studio where st_age>30)
--============一個(gè)分頁的SQL語句======== select top 3 * from studio where st_id>all(select top 3 st_id from studio order by st_id) order by st_id
--使用 exists ,該關(guān)鍵字引入一個(gè)子查詢的時(shí)候基本上是對數(shù)據(jù)進(jìn)行一次是否存在的測試 --我們查詢那些人所在的班級(jí)是編號(hào)為 1 的 select * from studio where exists(select cl_id from class where studio.cl_id=class.cl_id and class.cl_id=1) --使用 not exists select * from studio where not exists(select * from class where studio.cl_id=class.cl_id and class.cl_id=1) order by st_id
--基于查詢生成新的表 select st_name into class_3 from studio where cl_id=3
--將數(shù)據(jù)批量插入一個(gè)表中 insert into class_3 select st_name from studio where cl_id=4
【 1 】 【 2 】 【 3 】 【 4 】 【 5 】 |
|
|
|