我有以下查询:
select U.IdUser,U.memberID,SL.Title from users U
inner join statuslist SL on
U.idStatus=SL.IdStatus
where U.idOrg='1'and isnull(U.memberID,'')!=''
order by U.memberID
它给了我结果:
在这里,我希望B12会员ID在B110之前出现(意味着12来自110之前的原因)。
我怎样才能实现它?
我在下面试过......
select U.IdUser,U.memberID,SL.Title from users U
inner join statuslist SL on
U.idStatus=SL.IdStatus
where U.idOrg='1'and isnull(U.memberID,'')!=''
order by Substring(U.memberID,2,LEN(U.memberID))
但没有给出正确的结果。
请帮帮我。
答案 0 :(得分:1)
这是因为order by with strings
和order by with numbers
:
select U.IdUser,U.memberID,SL.Title from users U
inner join statuslist SL on
U.idStatus=SL.IdStatus
where U.idOrg='1'and isnull(U.memberID,'')!=''
order by CAST(Substring(U.memberID,2,LEN(U.memberID)-1) AS INT);
select U.IdUser,U.memberID,SL.Title from users U
inner join statuslist SL on
U.idStatus=SL.IdStatus
where U.idOrg='1'and isnull(U.memberID,'')!=''
order by CONVERT(INT,Substring(U.memberID,2,LEN(U.memberID)-1));