select top 5 * from MainClass ,SubClass  where 连接条件

解决方案 »

  1.   

    select name=(select name from MainClass),a.* from (select top 5 * from  SubClass)a
      

  2.   

    --合并字符串问题
    create table tbltest(列A int,列C varchar(100))
    go
    insert into tbltest
    select 1,'A' union all
    select 1,'B' union all
    select 1,'C' union all
    select 1,'F' union all
    select 1,'G' union all
    select 2,'E' union all
    select 2,'F' union all
    select 2,'F'
    go--写一个聚合函数:
    create function dbo.fn_Merge(@F1 int)
    returns varchar(8000)
    as
    begin
       declare @r varchar(8000)
       set @r=''
       select @r=@r+','+列C from tbltest where 列A=@F1
       return stuff(@r,1,1,'')
    end
    go-- 调用函数
    select 列A, dbo.fn_Merge(列A) as 列C 
    from tbltest 
    group by 列A
    go--删除测试数据
    drop table tbltest
    drop function fn_Merge--查看结果
    /*
    列A  列C
    1    A,B,C,F,G
    2    E,F,F
    */
      

  3.   

    以上1,2就是大类,A,B,C,F,G;E,F,F就是小类