1、在oracle中有一个表,表中的数据如下:      姓名  课程  成绩      张三  语文  20      张三  数学  30      张三  英语  40      要求用select语句将结果显示为:     姓名  语文  数学   英语     张三  20    30      40 2、在oracle中有个emp表,表中有empid,name,sal(工资)三列数据,现在要求查询工资至少比5个人高的所有人的          empid,name,sal和工资低于他的人数。 3、在oracle中有一个person表,表中的数据如下:      id          age     001         30     002        36     003        58     004         27     005        58   其中age可以相同,现要求查询age最大的id最小的纪录。
 

解决方案 »

  1.   

    1select 姓名,sum(decode(课程,'语文', 成绩 ,0)) 语文,sum(decode(课程,'数学', 成绩 ,0)) 数学,sum(decode(课程,'英语', 成绩 ,0)) 英语
    from table
    group by 姓名
      

  2.   

    2
    在oracle中有个emp表,表中有empid,name,sal(工资)三列数据,现在要求查询工资至少比5个人高的所有人的                     empid,name,sal和工资低于他的人数。  
    select a.empid,a.name,a.sal,a.rn-1
    from
    (select row_number() over(order by sal desc) rn,empid,name,sal
    from emp
    ) a
    where rn>5
    其中a.rn-1就是工资低于他的人数
      

  3.   

    XD, 回去好好看看书哦~~ 嘿嘿... 
    是作业吗?总感觉是不是面试题 ...
    1: select tt.sna,
           max(decode(tt.course,'yuwen',tt.score)) as "yuwen",
           max(decode(tt.course,'shuxue',tt.score)) as "shuxue",
           max(decode(tt.course,'yiyu',tt.score)) as "yiyu"
      from tablename tt
     group by tt.sna;
    SNA           yuwen     shuxue       yiyu
    -------- ---------- ---------- ----------
    zhangsan         20         30         402:  select tt.empid,
            tt.name,
            tt.sal,
            tt.rn - 1 as "Person_Count"
       from (
             select e.*,
                    rank() over(order by e.sal) as rn
               from emp e
            )tt
      where tt.rn > 5;3:select *
      from person t3
     where exists (
                      select 1
                        from person t2
                       where not exists (select 1
                                           from person t1
                                          where t2.age < t1.age
                                         )
                         and t3.age = t2.age
                         and t3.sid < t2.sid 
                      );SID        AGE
    --- ----------
    003         58
      

  4.   

    3、在oracle中有一个person表,表中的数据如下:             id                     age           001                   30           002                 36           003                 58           004                   27           005                 58       其中age可以相同,现要求查询age最大的id最小的纪录。 select a.id,a.age
    from
    (
    select min(id) id,age
    from person
    group by age
    ) a,
    (
    select max(age) age
    from person
    ) b
    where a.age=b.age
      

  5.   

    1为经典的行列转化,固定的列用decode.以前论坛出现过的
      

  6.   

    这三道题确实是面试题,当时我没有做出来。这是小弟第一次在CSDN提问,谢谢各位大侠的回复了。那两位给了答案的大虾我各给了10分,不要嫌少,真的谢谢你们了。