SQL SUM question

后端 未结 5 1332

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:47

    SUM is an aggregate function. This means you can aggregate data from a field over several tuples and sum it up into a single tuple.

    What you want to do is this:

    SELECT 
      table_one.field + table_two.field,
      table_one.field + table_two.field + table_one.anotherfield
    

    or maybe this:

    SELECT 
      SUM(table_one.field) + SUM(table_two.field),
      SUM(table_one.field) + SUM(table_two.field) + SUM(table_one.anotherfield)
    

提交回复
热议问题