About 3,110,000 results
Open links in new tab
  1. SQL sum with condition - Stack Overflow

    Dec 23, 2010 · SQL SUM with Conditions. 2. sum columns in sql depending on condition. 0. Sum having a condition. 0. SUM ...

  2. How can I sum a group of sums? SQL Server 2008 - Stack Overflow

    Mar 8, 2011 · It sounds like you need to group by just Table1.ID instead. SELECT Table1.ID, SUM(Table2.[Number1] + Table2.[Number2]) AS SumColumn FROM Table1 INNER JOIN Table3 ON Table1.ID = Table3.ID INNER JOIN Table2 ON Table3.ID = Table2.ID WHERE (Table2.[Something] = 'Whatever') GROUP BY Table1.ID

  3. use mysql SUM () in a WHERE clause - Stack Overflow

    You can use a derived table to join each row to the group of rows with a lesser id value, and produce the sum of each sum group. Then test where the sum meets your criterion. CREATE TABLE MyTable ( id INT PRIMARY KEY, cash INT ); INSERT INTO MyTable (id, cash) VALUES (1, 200), (2, 301), (3, 101), (4, 700); SELECT s.*

  4. sql - Cumulating value of current row + sum of previous rows

    I use this last SQL command in my VB.Net - Postgresql application. To compute more that one year knowing Balance value on 1 January 2010, I use following SQL command. SELECT Yearx ,NoSeq ,Amount ,-279.34 + SUM(Amount) OVER(ORDER BY Yearx,NoSeq) as balance FROM payements WHERE Yearx BETWEEN 2010 AND 2021

  5. SUM of grouped COUNT in SQL Query - Stack Overflow

    Feb 19, 2022 · SQL Fiddle DEMO SELECT Name, COUNT(1) as Cnt FROM Table1 GROUP BY Name UNION ALL SELECT 'SUM' Name, COUNT(1) FROM Table1 That said, I would recomend that the total be added by your presentation layer, and not by the database. This is a bit more of a SQL SERVER Version using Summarizing Data Using ROLLUP. SQL Fiddle DEMO

  6. sql - Avg of a Sum in one query - Stack Overflow

    May 21, 2015 · SELECT AVG(asset_sums) FROM ( SELECT t.client, SUM(t.asset) AS asset_sums FROM the-table t GROUP BY t.client ) as inner_query You can't however group the outer query, because this will give you results like in the first query.

  7. SUMIFS (Sum if with multiple conditions) with SQL Server

    SUMIF can be replicated in SQL with SUM(case statement):. SELECT Type ,SUM(CASE WHEN Year = '2010' THEN Total ELSE 0 END)'2010 Total' ,SUM(CASE WHEN Year = '2010' THEN Total ELSE 0 END)*1.0/SUM(SUM(CASE WHEN Year = '2010' THEN Total ELSE 0 END)) OVER '2010 Percent of Total' ,SUM(CASE WHEN Year = '2011' THEN Total ELSE 0 END)'2011 …

  8. sql - Add a summary row with totals - Stack Overflow

    May 26, 2017 · If you are on SQL Server 2008 or later version, you can use the ROLLUP() GROUP BY function: SELECT Type = ISNULL(Type, 'Total'), TotalSales = SUM(TotalSales) FROM atable GROUP BY ROLLUP(Type) ; This assumes that the Type column cannot have NULLs and so the NULL in this query would indicate the rollup row, the one with the grand total.

  9. Multiply 2 columns in sql and to sum all the results using SQL

    Jul 22, 2011 · SQL SERVER - select sum of column value multiplied by the count of other column. 1. Multiply two columns ...

  10. sql - How to assign a sum of values within fields to a variable ...

    Aug 29, 2018 · I have an SQL statement which selects various data from a table in my database and I have declared variables within my code like: DECLARE @TotalAge int; Let's say one of the fields in the table is Age, how would I sum the collected values from the query and assign them to the variable as a total?

Refresh