SQL Add Column Values

How to add values ​​to SQL column? I have a table configured in xampp and I'm trying to add all the values ​​in a column called "gross".

+7
source share
3 answers

SQL Server or MySQL:

select sum(MyColumn) as MyColumnSum from MyTable 

If you need to summarize a column by grouping another column

 select sum(MyColumn) as MyColumnSum, OtherColumn from MyTable Group By OtherColumn 

Here is a way to individually add negative or positive numbers

 select sum( case when MyColumn < 0 then MyColumn else 0 end ) as NegativeSum, sum( case when MyColumn > 0 then MyColumn else 0 end ) as PositiveSum from MyTable 

Link

+12
source
 select sum(yourCol) as Gross from YourTable 

Use the aggregate function SUM ().

+1
source

Take a look at the SUM() function documentation for MySQL .

 SELECT YourRecordID, SUM(Gross) AS GrossSum FROM YourTable GROUP BY YourRecordID 
+1
source

All Articles