---使用北風資料庫
Use Northwind
/*
使用Order By
*/
--列出北美地區客戶
Select *
from dbo.Customers
where Country in ('Canada','USA','Mexico')
order by Country ---ASC--預設(升冪)
----列出北美地區客戶
Select *
from dbo.Customers
where Country in ('Canada','USA','Mexico')
Order by Country desc--(降冪)
---列出客戶指定排序(1.USA 2.UK 3.Germany 4.France 5.其他用升冪)
Select *
from dbo.Customers
order by case when Country='USA' then 1 when Country='UK' then 2 when Country='Germany' then 3 when Country='France' then 4 else 5 end,Country asc
沒有留言:
張貼留言