我正在尝试做与此问题类似的事情。我有这张桌子:
tab_id
是第二列。order_in_tab
是第四列。
我想按tab_id
等于2
先的顺序排列,然后tab_id
依次order_in_tab
递增其余部分,然后递增。
select *
from cam_to_tab_mapping
where unit_id='90013550'
order by (tab_id='2') asc, tab_id asc, order_in_tab asc
但是,它说Incorrect syntax at '='.
。我是一名完全的SQL新手,所以我不确定什么地方出了问题(或者我是否误解了上面的链接解决方案)。
尝试像这样更改查询:
select *
from cam_to_tab_mapping
where unit_id='90013550'
order by CASE WHEN tab_id='2' THEN 1 ELSE 0 END DESC, tab_id asc, order_in_tab asc
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句