当前位置: 代码迷 >> Sql Server >> 求sql语句分组显示有关问题
  详细解决方案

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

热度:24   发布时间:2016-04-27 12:20:41.0
求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*/
------解决方案--------------------
楼上正解,沙发。
  相关解决方案