select id,name,age,count(*)
group by id,name,age
上面这段语句是可以通过的但
select id,name,age,count(*)
group by id,name
为什么通不过?select id,name,age,count(*)
又为什么通不过??

解决方案 »

  1.   

    select id,name,total(age),count(*)
    group by id,name
      

  2.   

    查询的内容, 要么使用聚合函数,要么放到group by 后面
      

  3.   

    age 不在分组之内,要加聚集函数如min(age)
      

  4.   

    查询的内容, 使用聚合函数时 字段放到group by 后面
      

  5.   

    select语句后面有多少字段,group by后面也必须(重要)有多少字段。
    但是(重要)聚合函数出外。
    这就是你上面第一个可以。后面几个不行的原因。
      

  6.   

    yulingrqz(闻香泣血)兄弟挺逗!
    我是不小心发的,没想到yulingrqz(闻香泣血)兄弟跟着我发了二个:)
      

  7.   

    使用聚合函数必须使用group by ,这是语法要求!
      

  8.   

    create table em
    (ID int  not null,
    name varchar(20),
    age smallint)insert em(id,name,age)
              select 1,'张三',10
    union all select 1,'李四',20
    union all select 1,'李四',20
    union all select 2,'王五',30
    union all select 3,'赵六',40
    --select * from em--就是这行了。
    --看你的需要应该不用把名字也分组吧!?
    select ID,name,age, (select count(*) from em where id=e.id and name=e.name group by id,name) as 分组记录数 from em edrop table em