id      name     course  score   
001     小王      数学     68
002     张三      数学     85
001     小王      语文     36
003     李四      英语     69
002     张三      语文     98
003     李四      语文     82
003     李四      地理     67请问如何输出列id中各个值出现的次数。
结果如下所示
001  2
002  2
003  3还有,我想输出修满3门课程且每门课程的成绩都大于60分人的姓名,请问如何写Sql语句。非常感谢!

解决方案 »

  1.   

    select id count(1) as 出现的次数 from tb group by id
      

  2.   

    select id count(distinct(姓名)) as 出现的次数 from tb group by id
      

  3.   

    select id,count(1) as 出现的次数 from tb group by id
      

  4.   

    select id count(1) as 出现的次数 from tb group by id having(count(1)>=3 and 分数>60)
      

  5.   

    select id, count(1) as 出现的次数 from tb group by id having(count(1)>=3 and 分数>60)
    多谢三楼提示
      

  6.   


    select id,count(1) as 出现的次数 from tb group by id
      

  7.   


    -- 1.输出列id中各个值出现的次数
    SELECT id,COUNT(id) AS COUNTS FROM Score GROUP BY id-- 2.修满3门课程且每门课程的成绩都大于60分人的姓名SELECT name FROM Score A 
    WHERE A.score > 60
    GROUP BY name
    HAVING COUNT(name) = 3
      

  8.   

     select distinct(id),count(id)from 表 order by idselect *,count(id)from 表 where order by id having(count(id)>=3 and scoure>60)
      

  9.   

    我想应该这样写,因为可能出现同名的情况
    select * from test where id in
    (
    select id from test
    where score>=60
    group by id
    having count(id)=15
    )
    order by id现在又一个奇怪的问题,
    select id from test
    where score>=60
    group by id
    having count(id)=15
    这一句的执行结果id没有重复值,但是下面一句
    select id,count(id)from test
    where cj>=60
    group by id
    having count(id)=15
    中的count(id)
    的值却大于1,id的值不是不重复吗?怎么会出现这这种情况啊?谢谢!
    --我在数据库中添加了很多数据。