这样应该就是你要的逻辑select field1, sum(field2) 
from table1  
group by field1
select sum(field2) from table1 t1 where t1.field1 = field1 group by t1.field1
==>
select sum(field2) from table1 t1 where t1.field1 = field1 
因为在一行里,t1.field1是一个特定的值

解决方案 »

  1.   

    select   field1,   (select   sum(field2)   from   table1   t1   where   t1.field1   =   field1 )  as field2
    from   table1   
    group   by   field1 
      

  2.   

    select   field1,   
    (select   sum(field2)   from   table1     where   t1.field1   =   field1 )  as field2
    from   table1   t1--别名放在外面
    group   by   field1 
      

  3.   

    5楼中给出的代码:
    select   field1,   (select   sum(field2)   from   table1   t1   where   t1.field1   =   field1 )  as field2
    from   table1   
    group   by   field1 如果 (select   sum(field2)   from   table1   t1   where   t1.field1   =   field1 )  as field2
    中的table1 t1 是一个查询出来的表呢?
    例如:要统计的表不再是table1而是一个复杂查询:
    select sum(field3) from table3 where field1 in(select distinct field1 from table1 where field is not null)
    这个时候语法会通过吗?