Is there any way to make first row be different then the rest, so it would show total sum of the appropriate columns?
For example:
fruits|a|b|c
total|3|4|6
apples|1|2|3
bananas|1|1|2
oranges|1|1|1
Is it possible to make query like that or it is against the logic of sql?
It would be like this (ignoring the first row for now):
SELECT fruits, sum(a), sum(b), sum(c)
FROM basket
So the first row would be different. It would show word ‘total’ instead of fruit name, and would show total sum of a (1+1+1=3), b (2+1+1=4) and c (3+2+1=6). Is it possible to do like that? Thanks
You can avoid a second full scan of the table with a CTE:
PostgreSQL 9.2 Schema:
Query:
Results:
SQL Fiddle here