SQL SUM question

后端 未结 5 1273

Hi I have a question about SUM in sql,

I have a query that looks like this

SELECT 
 SUM ( table_one.field + table_two.field )  as total_field
 SUM ( tota         


        
5条回答
  •  深忆病人
    2021-01-28 11:45

    You cannot use the column alias in an aggregate to reference the value, just SUM again;

    SELECT 
     SUM ( table_one.field + table_two.field ) as total_field, --your missing a , also
     SUM ( table_one.field + table_two.field + table_one.anotherfield )
    FROM 
     table_one
    JOIN
     table_two ON table_one.id = table_two.id
    WHERE 
     table_one = 1
    

提交回复
热议问题