select * from user aa left join type bb on aa.type=bb.type
where (select count(*) from User aaa where aaa.type=aa.type and aaa.id<=aa.id)<=bb.row

解决方案 »

  1.   

    create table #type (id int,type varchar(10),row  int)
    create table #use (id int,[name] varchar(10),type varchar(10))
    declare @str varchar(1000)
    set @str=''
    insert #type values(1,'大专',2)
    insert #type values(1,'本科',1)
    insert #use values(1     ,'a'   ,  '大专'    )
    insert #use values(2     ,'b'   ,  '大专' )       
    insert #use values(3     ,'c'   ,  '大专'  )      
    insert #use values(4     ,'d'   ,  '本科'  )      
    insert #use values(5     ,'e'   ,  '本科'  )
    select @str=@str+ 'select top ' + cast(row as varchar(10)) + ' * from #use where type=''' + type + ''' union all '  from #type  
    set @str=left(@str,len(@str)-9)
    exec(@str)
      

  2.   

    create table #type (id int,type varchar(10),row  int)
    create table #use (id int,[name] varchar(10),type varchar(10))
    declare @str varchar(1000)
    set @str=''
    insert #type values(1,'大专',2)
    insert #type values(1,'本科',1)
    insert #use values(1     ,'a'   ,  '大专'    )
    insert #use values(2     ,'b'   ,  '大专' )       
    insert #use values(3     ,'c'   ,  '大专'  )      
    insert #use values(4     ,'d'   ,  '本科'  )      
    insert #use values(5     ,'e'   ,  '本科'  )
    select @str=@str+ 'select top ' + cast(row as varchar(10)) + ' * from #use where type=''' + type + ''' union all '  from #type  
    set @str=left(@str,len(@str)-9)
    exec(@str)
      

  3.   

    select  a.* from [use] a ,type b where a.type=b.type and (select count(*) from [use] aa where a.type=aa.type and a.id>=aa.id)<=b.row
      

  4.   

    select A.* 
    from [use] A left join type B on A.type = B.type
    where (select count(*) from [use] C 
           where C.type = A.type and C.id< = A.id) <= B.row
      

  5.   

    SELECT A.* 
    FROM [use] A LEFT JOIN type B ON A.type = B.type
    WHERE (SELECT COUNT(*) FROM [Use] C 
           WHERE C.type = A.type AND C.id <= A.id) <= B.row
      

  6.   

    谢谢大家支持, 我不只太懂
    a.id>=aa.id是什么意思,为什么要写可以不写吗?
      

  7.   

    a.id>=aa.id,不能不写的,其实也就是确定一个顺序,有了一个顺序,就可以判断这些记录是不是在你的ROW值所指定的范围内,如果没有这个顺序,也就没有办法判断取N条中的哪个row条记录.
      

  8.   

    a.id>=aa.id,不能不写的,其实也就是确定一个顺序,有了一个顺序,就可以判断这些记录是不是在你的ROW值所指定的范围内,如果没有这个顺序,也就没有办法判断取N条中的哪个row条记录.