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
标签:varchar,pid,len,sql,字符串,排序,id,left From: https://www.cnblogs.com/lb809663396/p/16880417.html