一张数据表中有 word1,word2,wordid,wordnum,请问下面的语句为何会出错?select * from V3DWORD 
where WordNum > 100 
group by word1
having COUNT(word1) > 10错误:消息 8120,级别 16,状态 1,第 1 行
选择列表中的列 'V3DWORD.Word2' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。

解决方案 »

  1.   

    select word1,COUNT(word1)
     from V3DWORD 
        where WordNum > 100 
            group by word1
                having COUNT(word1) > 10
      

  2.   

    用了group by之后,所有没有被聚合函数包住的列都必须出现在group by中
      

  3.   

    group by 之后跟 你select 出的所有列名。
    group by word1,word2....... 
      

  4.   

    大哥语句错的离谱啊,
    按照word1分组为什么还会count(word1)>10这根本不可能数据啊
      

  5.   

    group by word1,word2,wordid,wordnum --有几列就group by几列
    或select word1 from V3DWORD 
        where WordNum > 100 
            group by word1
                having COUNT(word1) > 10
      

  6.   

    有group by  的语句,select 中的列就必须是聚合函数 或者 列都写在group by后面
      

  7.   

    select  word1,count(word1)
     from V3DWORD 
     where WordNum > 100 
     group by word1
     having COUNT(word1) > 10
      

  8.   

    可能有数据。
    declare @tab table(id int)
    insert into @tab
    select 1 union all
    select 1 union all
    select 1 union all
    select 2
    select id,count(id) from @tab
    group by id 
    having count(id)>2
      

  9.   

    sql语句中含有group by子句,select的列必须是group by 后面的字段 或是聚合函数。