溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

測試需要知道的9條基本sql語句

發(fā)布時(shí)間:2020-07-21 21:05:10 來源:網(wǎng)絡(luò) 閱讀:11018 作者:瑟瑟發(fā)抖de 欄目:MySQL數(shù)據(jù)庫

1、測試需要學(xué)習(xí)簡單的基本的sql語句
選擇:select from table1 where 范圍
插入:insert into table1(field1,field2) values(value1,value2)
刪除:delete from table1 where 范圍
更新:update table1 set field1=value1 where 范圍
查找:select
from table1 where field1 like ’%value1%’ ---like的語法很精妙,查資料!
排序:select from table1 order by field1,field2 [desc]
總數(shù):select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最?。簊elect min(field1) as minvalue from table1
2、說明:復(fù)制表(只復(fù)制結(jié)構(gòu),源表名:a 新表名:b) (Access可用)
法一:select
into b from a where 1<>1(僅用于SQlServer)
法二:select top 0 * into b from a
2、說明:拷貝表(拷貝數(shù)據(jù),源表名:a 目標(biāo)表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;

3、說明:跨數(shù)據(jù)庫之間表的拷貝(具體數(shù)據(jù)使用絕對路徑) (Access可用)
insert into b(a, b, c) select d,e,f from b in ‘具體數(shù)據(jù)庫’ where 條件
例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..

4、說明:子查詢(表名1:a 表名2:b)
select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)

5、說明:外連接查詢(表名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

6、說明:兩張關(guān)聯(lián)表,刪除主表中已經(jīng)在副表中沒有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

7、說明:四表聯(lián)查問題:
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 .....

8、說明:一條sql 語句搞定數(shù)據(jù)庫分頁
select top 10 b.* from (select top 20 主鍵字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主鍵字段 = a.主鍵字段 order by a.排序字段

9、說明:列出數(shù)據(jù)庫里所有的表名
select name from sysobjects where type='U' // U代表用戶

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI