SQL條件語(yǔ)句實(shí)例
在SQL語(yǔ)句中,SQL條件語(yǔ)句無(wú)疑是使用最廣,最常見的SQL語(yǔ)句之一,下面就將為您介紹幾個(gè)使用SQL條件語(yǔ)句,供您學(xué)習(xí)參考。
----查詢StudentMarks 最大的前三條記錄
select top 3 StudentID,StudentName,Mark from StudentMarks order by Mark desc
----查詢StudentMarks 的第30~40條記錄
1、從前30條的后面, 取前10條
select top 10 * from StudentMarks where StudentID not in(select top 30 StudentID from StudentMarks)
2、先正序取40條, 再反序取10條
select top 10* from (select top 40* from StudentMarks order by Mark ) a
order by Mark desc
3、、利用臨時(shí)表
select top 40 * into #Stm from StudentMarks order by Mark
select top * from #Stm order by Mark desc
----查詢和London同屬于一個(gè)國(guó)家的城市的客戶
select distinct * from customers where country in
( select country from customers where city='London') 
----查詢和London,Paris同屬于一個(gè)國(guó)家的城市的客戶
select * from customers where country in 
(select country from Customers where City in ('London','Paris'))
----查詢單價(jià)大于Dofu的產(chǎn)品名
select ProductName from Products where UnitPrice>
(select UnitPrice from Products where ProductName='Tofu')
【編輯推薦】
SQL整體更新的方法















 
 
 


 
 
 
 