本文介绍了如何在sql中获取第一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张类似
的桌子
i have a table like
Currencyid C_Title
1 USD
2 INR
3 CAD
4 EUR
5 EGP
Select * from Currency Order by C_Title
结果如下:
Result comes this:
Currencyid C_Title
3 CAD
5 EGP
4 EUR
2 INR
1 USD
但我的要求是:
but my requirement is :
Currencyid C_Title
2 INR
3 CAD
5 EGP
4 EUR
1 USD
推荐答案
Select 1 as displayorder,Currencyid,C_Title from @Currency where C_Title = 'INR'
union all
Select 2 as displayorder,Currencyid, C_Title from @Currency where C_Title <> 'INR'
order by displayorder, C_Title
SELECT CurencyId, C_Title FROM MyTable
ORDER BY
( CASE
WHEN C_Title='INR' THEN 0
WHEN C_Title='CAD' THEN 1
WHEN C_Title='EGP' THEN 2
WHEN C_Title='EUR' THEN 3
WHEN C_Title='USD' THEN 4
ELSE CurrencyId
END )
这篇关于如何在sql中获取第一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!