一楼说得不够清楚这句语句返回两种结果:select * from a order by 1, nameselect * from a order by 0, name但是这两句在语法上都行不通啊. 请详细点解释, 不能理解啊
case name when 'ert' then 1 else 0 end 楼主可以把上面看成一个新字段.
tryselect *,newcol=case name when 'ert' then 1 else 0 end from a order by case name when 'ert' then 1 else 0 end , name
这样就可以理解 select * from a order by case name when 'ert' then 1 else 0 end 这个不能理解, 为什么在后面加 ,name 也不提示语法错误? select * from a order by case name when 'ert' then 1 else 0 end , name
这样就可以理解 select * from a order by case name when 'ert' then 1 else 0 end 这个不能理解, 为什么在后面加 ,name 也不提示语法错误? select * from a order by case name when 'ert' then 1 else 0 end , name
order by 后面本来就可以跟多个字段排序啊,有什么不理解?比如: id name 1 a 1 b 1 a 2 b 2 aorder by id的话,只能保证按id排序,不能保证id相同时,按name排序 order by id,name就可以实现
楼主可以把上面看成一个新字段.
order by case name when 'ert' then 1 else 0 end , name
select * from a
order by case name when 'ert' then 1 else 0 end
这个不能理解, 为什么在后面加 ,name 也不提示语法错误?
select * from a
order by case name when 'ert' then 1 else 0 end , name
select * from a
order by case name when 'ert' then 1 else 0 end
这个不能理解, 为什么在后面加 ,name 也不提示语法错误?
select * from a
order by case name when 'ert' then 1 else 0 end , name
id name
1 a
1 b
1 a
2 b
2 aorder by id的话,只能保证按id排序,不能保证id相同时,按name排序
order by id,name就可以实现