编号 课名
a1   语文
a1   数学
a2   office
a3   电脑
a3   数学
a2   电脑
a1   电脑sql該如何呈現資料
课程 学生编号
电脑课 a1
       a2
       a3

解决方案 »

  1.   

    select 课名,编号 from table where 课名 in(
    select 课名 from(
    select 课名,count(*) sl from table a  group by position order by count(*) desc ) where rownum='1')
    额,MAX应该也行,忘了怎么用了,就直接排倒序取第一行了
      

  2.   

    不行
    一直在order by 那边说"遗漏了一个又括弧"
      

  3.   

    select 编号,课名 
    from tb 
    where 课名=(select 课名 from 
    (select 课名,count(*) from tb group by 课名 order by count(*) desc) where rownum<2)
      

  4.   

    select * from (
    with t as
    (
    select 'a1' bh,'语文' km from dual
    union all
    select 'a1' bh,'数学' km from dual
    union all
    select 'a2' bh,'office' km from dual
    union all
    select 'a3' bh,'电脑' km from dual
    union all
    select 'a3' bh,'数学' km from dual
    union all
    select 'a2' bh,'电脑' km from dual
    union all
    select 'a1' bh,'电脑' km from dual
    )
    select wmsys.wm_concat(bh) 学员,count(*) 热度 from t group by km
    ) v order by 热度 desc
      

  5.   


    create table tb(
    a char(10) ,
    b char(10)
    )
    insert into tb
    VALUES ('a1' , '语文')
    insert into tb
    VALUES ('a1' , '数学')
    insert into tb
    VALUES ('a2' , 'office')
    insert into tb
    VALUES ('a3' , '电脑')
    insert into tb
    VALUES ('a3' , '数学')
    insert into tb
    VALUES ('a2' , '电脑')
    insert into tb
    VALUES ('a1' , '电脑')select * from tb 
    where b in (
    select top 1 b from tb t2 group by b  order by count(b) desc
    )
      

  6.   

    select 编号,课名 from tab where 课名 in (select name2 from (SELECT name2, count(name2) cnt FROM tab group by name2 order by cnt) t where rownum = 1)
      

  7.   

    两个地方想请教
    1.在执行时order by的前面总会出现少了括弧
    2.rownum = 1→要挑出店选最多次的课程名称如果每个课程都只有一人点选呢??这样会出来吗?