求一个SQL语句

VIV777 2006-10-30 04:50:03
请教一个SQL语句,例如
表station
select arearid ,stationname,stationinputcode from station where stationinputcode
like '%w%' order by stationinputcode
查询结果:
areaid stationname stationinputcode
1 毕家洼小区 BJWXQ
1 产业园管委会 CYYGWH
1 创业服务中心 CYFWZX
1 大王村 DWC
1 大魏 DW
1 甸柳新村五区 DLXCWQ
1 东八里洼 DBLW
1 省印刷物资公司 SYSWZGS
1 王舍人镇政府 WSRZZF
1 文化东路东口 WHDLDK
。。。。。。。
我想问一下,如何通过写SQL语句实现下面这个结果:
areaid stationname stationinputcode
1 文化东路东口 WHDLDK
1 王舍人镇政府 WSRZZF
1 大魏 DW
1 大王村 DWC
1 毕家洼小区 BJWXQ
。。。。。。。
就是先出现以W开头,其余的按字母顺序出现的所有结果,
然后W是第二个字母,其他的再按字母顺序出现所有结果
W是第三个字母,其他的再按字母顺序出现所有结果
依次类推









...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
VIV777 2006-10-30
  • 打赏
  • 举报
回复
呵呵,现在就结帖,谢谢了!
VIV777 2006-10-30
  • 打赏
  • 举报
回复
我想问一下i9988(冒牌j9988 V0.3),2147483647这是什么意思啊?
Softlee81307 2006-10-30
  • 打赏
  • 举报
回复

Create table station(areaid int,stationname varchar(20),stationinputcode varchar(20))
Insert into station
select 1, '毕家洼小区', 'BJWXQ' union all
select 1, '产业园管委会', 'CYYGWH'union all
select 1, '创业服务中心', 'CYFWZX'union all
select 1, '大王村', 'DWC'union all
select 1, '大魏', 'DW'union all
select 1, '甸柳新村五区', 'DLXCWQ'union all
select 1, '东八里洼', 'DBLW' union all
select 1, '省印刷物资公司', 'SYSWZGS'union all
select 1, '王舍人镇政府', 'WSRZZF'union all
select 1, '文化东路东口', 'WHDLDK'
-------------------------------------------------------
select * from station order by charindex('W',stationinputcode)
拓狼 2006-10-30
  • 打赏
  • 举报
回复
将order by stationinputcode 修改为

order by charindex('w',stationinputcode),stationinputcode
hhhdyj 2006-10-30
  • 打赏
  • 举报
回复
select arearid ,stationname,stationinputcode from station where stationinputcode
like '%w%' order by (case when left(stationinputcode ,1) = 'W' then 'a' + stationinputcode else 'b' + stationinputcode end)
i9988 2006-10-30
  • 打赏
  • 举报
回复
select arearid ,stationname,stationinputcode from station where stationinputcode
like '%w%' order by case when charindex('W',stationinputcode)<=0 then 2147483647 else charindex('W',stationinputcode) end,stationinputcode

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧