有如下表:姓名 课程 成绩
===================================
张三 计算机基础 80
李四 计算机基础 90
张三 DELPHI程序设计 90
李四 delphi程序设计 80
王五 DELPHI程序设计 90
张三 哲学 90
李四 哲学 80
王五 哲学 90
………………
………………现要查询出第二个课程(即DELPHI程序设计)的所有学生成绩。
说明一下,用的paradox数据库。

解决方案 »

  1.   

    select * from yourtable where 课程='DELPHI程序设计'
      

  2.   

    select * from yourtable where 课程='DELPHI程序设计' order by 成绩 desc ;
      

  3.   

    select * from yourtable where 课程='DELPHI程序设计' order by 成绩 asc 蹭分
      

  4.   

    晕,上面的方法,我又不是白痴,当然晓得,我的意思是自动分出来,只要第二个课程,不一定就是“DELPHI程序设计”,可能是其他的,而且是动态的。
      

  5.   

    就像在SQL SERVER中的 Select Top 10 * from TableName 一样,只是这是取前10个我的要求是取第二个,而且要是"课程"名称和第二个一样的所有记录
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
      

  6.   

    顺序没有,我想用 order by先对 课程 排序出来吧
      

  7.   

    试试
    select * from t1 where 课程=(select top 1 课程 from t1 Group by 课程 having Test1<>(select top 1 课程 from t1 Group by 课程))
      

  8.   

    select a.* from tbl a, (select distinct 课程 from tbl where 课程 in (select top 2 课程 from tbl group by 课程) and not 课程 in (select top 1 课程 from tbl group by 课程)) b where a.课程=b.课程
      

  9.   

    select * from t1 
    where 课程=(select top 1 课程 from t1 
    where 课程<>(select top 1 课程 from t1 Group by 课程 order by 课程) Group by 课程) order by 课程
    姓名         课程                   成绩     
    ---------- -------------------- ------ 
    李四         计算机基础                90
    张三         计算机基础                80
      

  10.   

    谢谢楼上二位的回答,
    意思是非常明白了
    但是在paradox中,好像不能用 select top 1 * 这样的语句,我在SQL Expoler中提示错误
      

  11.   

    但用在delphi控件里,是肯定能通过!
      

  12.   

    select * from guest where 课程名 in (select 课程名 from (select distinct top 2 课程名 from guest) as tmp where id not in (select distinct top 1 课程名 from guest) )
      

  13.   

    paradox 中不能用 top 这个关键字呀
      

  14.   

    select * from 表 where 课程='DELPHI程序设计'
      

  15.   

    with ADOQuery1 do
    begin
    SQL.Clear;
    Query1.SQL.Add('select * from 表 where 课程='''DELPHI程序设计'''');
    Query1.ExecSQL;
    end;
      

  16.   

    如果你觉得这不够灵活的话建议你用这个方法:
    with ADOQuery1 do
    begin
    SQL.Clear;
    Query1.SQL.Add('select * from 表 where 课程='''+edit1.text+'''');
    Query1.ExecSQL;
    end;你可在运行的时候,在edit1.text里面输入“DELPHI程序设计”,就可以实现你想要的结果了,