读书人

这个结构怎么得到?等待中

发布时间: 2012-01-14 20:02:35 作者: rapoo

这个结构如何得到?等待中
表:CTpye
结构:(T_ID(identity),T_Name(varchar),T_Father(int))
数据如: 1,交通工具,0
2,汽车, 1
3,火车, 1
4,IT, 0
5,硬件, 4
6,软件, 4
7,自行车 1
....................
怎么能得到如下的形式:
T_ID,T_Name
1,交通工具
2,汽车
3,火车
4,自行车
5,IT
6,硬件
7,软件
4,IT

[解决办法]
select * from 表 order by (case T_Father when 0 then T_ID else T_Father end),T_ID

读书人网 >SQL Server

热点推荐