Skip to main content
Share Your Experience: Take the 2024 Developer Survey

New answers tagged

0 votes

How to Get the Sum (total) of a column in a query result set

Also: select column1 ,amount_column from dbo.tablename UNION select 'TOTAL' ,sum(amount_column) from dbo.tablename ;
johcar's user avatar
  • 1
0 votes

How to efficiently (O(log n)) get the sum over a range (date/time range) of a column?

Counting rows in PostgreSQL is always O(n), where n is the number of rows counted. If that is too slow for you, the usual remedy is to pre-aggregate the data, for example per user ID and day, so that ...
Laurenz Albe's user avatar
0 votes
Accepted

PostgreSQL - Sum all row that satisfy a condition into a single row

You can use another level of aggregation with a conditional value to group by. SELECT CASE WHEN jc.job_count >= 100 THEN jc.city ELSE 'Other cities' END AS city, SUM(jc.job_count) AS job_count, ...
Charlieface's user avatar
  • 13.2k

Top 50 recent answers are included