请用一句SQL取出成绩表(表名table1)中成绩(字段名P1)排名后30成绩的所有人员名单,请注意:如有并列成绩的人员,需要一并列出,例如成绩45分是后30名成绩,但得45分的有10人,那么这10人需要全部列出。求解答,希望能给出SQL语句。同时我本人在数据库方面操作得比较差,因此想大家给一些SQL语句学习方面的建议,或者能得到一些好的学习资料就最好了!谢谢!

解决方案 »

  1.   

    select * from table  order by 分数 limit 30;
      

  2.   

    select * from table1
    where P1 <= 
    (
    select max(P1)
    from (select top 30 * from table1 order by P1) a
    )
    SQLServer使用的是top 30,其他的数据库类似^_^
      

  3.   

    oracle用rownum,mysql的是:select * from table1 where P1 <=(select P1 from table1 order by P1 limit 30,1)
      

  4.   

    select * from table1
    where P1
    (select max(P1)
    from
    (select distinct top 30 P1 from table1 order by P1)
    )
      

  5.   


    select * from table1
    where P1<=
    (select max(P1)
    from
    (select distinct top 30 P1 from table1 order by P1)
    )
      

  6.   

    每个数据库的排序是不一样的,MySql可以用limit,oracle 可以用rank()、dense_rank
    http://oracle.chinaitlab.com/exploiture/831910.html
    LZ看下吧