读书人

求sql语句分组显示有关问题

发布时间: 2012-06-17 21:02:01 作者: rapoo

求sql语句分组显示问题
有个表table1:
字段:type Name
A类 A1
B类 B1
A类 A2
B类 B2

求sql语句分组显示出下面的结果:
字段:type Name
A类
A类 A1
A类 A2
B类
B类 B1
B类 B2




[解决办法]

SQL code
-->TravyLee生成测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([type] varchar(3),[Name] varchar(2))insert [test]select 'A类','A1' union allselect 'B类','B1' union allselect 'A类','A2' union allselect 'B类','B2'select distinct [type] as [type],[Name]='' from testunion allselect * from testorder by [type],[Name]/*type    NameA类    A类    A1A类    A2B类    B类    B1B类    B2*/
[解决办法]
楼上正解,沙发。

读书人网 >SQL Server

热点推荐