sql查询二级分类按照字符串排序
1.函数解释
len()是用来计算字符串长度
left()是用来截取指定部分的字符串
2.sql语句:
select id,pid from tb
order by case
when pid=0 then left('00000',5-len(id))+convert(varchar,id)
when pid<>0 then
left('00000',5-len(pid))+convert(varchar,pid)+left('00000',5-len(id))+convert(varchar,id)
end