About 112,000 results
Open links in new tab
  1. How to SUM two fields within an SQL query - Stack Overflow

    Feb 14, 2013 · If you want to add two columns together, all you have to do is add them. Then you will get the sum of those two columns for each row returned by the query. What your code is …

  2. SQL SUM operation of multiple subqueries - Stack Overflow

    Aug 13, 2013 · SELECT SUM(fare) as total_fare, SUM(cost) as total_cost as total_service_cost FROM ticket JOIN passenger ON passenger.ticket_id = ticket.id JOIN service ON …

  3. SQL sum with condition - Stack Overflow

    With condition HAVING you will eliminate data with cash not ultrapass 0 if you want, generating more efficiency in your query. SELECT SUM(cash) AS money FROM Table t1, Table2 t2 …

  4. sql server - How to get cumulative sum - Stack Overflow

    Jan 10, 2010 · Getting running totals in T-SQL is not hard, there are many correct answers, most of them pretty easy. What is not easy (or even possible at this time) is to write a true query in T …

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

    SELECT m1.id FROM mytable m1 INNER JOIN mytable m2 ON m1.id < m2.id GROUP BY m1.id HAVING SUM(m1.cash) > 500 ORDER BY m1.id LIMIT 1,2 The idea is to SUM up all the …

  6. sql - Select sum and inner join - Stack Overflow

    Jul 8, 2016 · The following SQL query. SELECT *, (SELECT SUM(amount) FROM transactions WHERE transactions.reference = bils.reference) AS paid FROM bills GROUP BY id HAVING …

  7. How to SUM and SUBTRACT using SQL? - Stack Overflow

    UPDATE stock_bal SET BAL_QTY = BAL_QTY - (SELECT SUM(QTY) FROM master_table GROUP BY master_table.ORDERNO, master_table.ITEM) This assumes you posted the …

  8. SQL - Sum of positive and negative numbers using subquery

    Dec 12, 2013 · For the sum of the negative : SELECT SUM(numberColumn) FROM tableFoo WHERE numberColumn < 0 For the sum of the positive: SELECT SUM(numberColumn) …

  9. Sql Subquery with sum - Stack Overflow

    Feb 8, 2010 · I have two tables Invoices and Payments. invoices have payments. I want to write a query that displays unpaid invoices and the remaining amount of the invoice, which is …

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

    Oct 17, 2012 · 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 …