首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-06-17 
求sql语句分组显示问题有个表table1:字段:typeNameA类A1B类B1A类A2B类B2求sql语句分组显示出下面的结果:字

求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*/
[解决办法]
楼上正解,沙发。

热点排行
Bad Request.