如图,请问如何写出这条语句呢??
如图,请问如何写出这条语句呢??

解决方案 »

  1.   

    我就是点了插入图片啊。。我的图片放在CSDN空间的相册里。。
      

  2.   

    直接把图片的链接也发上去吧
    http://hi.csdn.net/space-4493601-do-album-picid-862357.html
      

  3.   

    合并多行数据
    select 省,
       市(订单)=stuff((select ' '+市+'('+订单号+')' from tb where 省=a.省 for xml path('')),1,1,''),
     数量=stuff((select ' '+rtrim(数量) from tb where 省=a.省 for xml path('')),1,1,'')
    from tb a group by 省
      

  4.   

    select (case when 订单号=(select min(订单号) from tb a where a.省份=tb.省份) then 省份 else '' end ) as 省份,
           市+订单号 as [市(订单)],数量 from tb
      

  5.   


    use CubeDemo;
    go
    SET NOCOUNT ON
    if OBJECT_ID(N'A',N'U') is not null drop table A
    go
    create table A
    (
    省 nvarchar(100),
    市 nvarchar(100),
    订单号 nvarchar(100),
    数量 float
    )
    go
    insert into a
    select '广东','广州','0001',100 union all
    select '广东','深圳','0002',200 union all
    select '海南','海口','0003',300 union all
    select '海南','三亚','0004',400 
    goselect 省,
            (select 市+' ( '+订单+' ) ' from a where 省=m.省 for xml path('')) as '市(订单)'
            ,(select rtrim(数量)+ ' '  from a where 省=m.省 for xml path('')) as '数量'
    from a m group by 省
      

  6.   

    select
       case id when 1 then 身份 else '' end as 身份,
       市+'('+订单号+')' as [市(订单)]
    from
       (select id=row_number()over(partition by 身份 order by getdate()),* from tb)b