select count(id),id,stuname from student where classid=2
我想在学生表中查询班级是2班的所有学生数ID号和姓名 怎么就不对呢

解决方案 »

  1.   

    没有分组group by子句,所以错误了。
      

  2.   

    select id,stuname,学生数=(select count(1) where classid=2)
    from student where classid=2
      

  3.   


    select id,stuname,num = (select count(*) from sutdent where classid = 2)
    from student
    where classid = 2
      

  4.   


    select id,stuname from student where classid=2
      

  5.   

    select id,stuname,学生数=(select count(1) where classid=2)
    from student where classid=2  

    select id,stuname,学生数=(select count(1) where classid=2)
    from student where classid=2  group by id,stunamecount 是聚合函数 与聚合函数一起查询的列要进行分组  或者将聚合函数作为子查询
      

  6.   

    要么用group by分组。
    要么用嵌套子查询。