例:
---------------------------------------------- P.No | Relation | Name ---------------------------------------------- 2 | Self | Kumar ---------------------------------------------- 1 | Husband | Selvam ---------------------------------------------- 2 | Son | Manoj ---------------------------------------------- 1 | Self | Gandhi ----------------------------------------------
如何基于列值首选项的行?
我想要这样的东西:
Order By P.No & ( Self 1 st preference , Husband 2nd preference, son 3rd Preference )
而且我期待这个输出:
---------------------------------------------- P.No | Relation | Name ---------------------------------------------- 1 | Self | Gandhi ---------------------------------------------- 1 | Husband | Selvam ---------------------------------------------- 2 | Self | Kumar ---------------------------------------------- 2 | Son | Manoj ----------------------------------------------
请帮我解决我的问题.谢谢.
你想将三元组翻译(Self, Husband, Son)
成某种东西,这是比较的.有几种方法可以做到这一点:
天真的方式:
ORDER BY IF(Relation="Self",0,IF(Relation="Husband",1,2))
或者时髦的方式:
ORDER BY (Relation="Self")+2*(Relation="Husband")+3*(Relation="Son")