Id | Type | Val |
---|---|---|
1 | a | 2 |
2 | b | 5 |
3 | b | 3 |
1 | b | 4 |
4 | x | 5 |
6 | b | 5 |
2 | c | 3 |
2 | d | 2 |
1 | x | 2 |
4 | b | 3 |
6 | c | 2 |
4 | d | 3 |
Id | Sum | Category |
---|---|---|
1 | 6 | alpha |
1 | 2 | beta |
2 | 5 | alpha |
2 | 5 | beta |
3 | 3 | alpha |
4 | 3 | alpha |
4 | 8 | beta |
6 | 5 | alpha |
6 | 2 | beta |
one query is performed and joined it to a table
Paul Clapham wrote:I would do the two queries and combine them with "UNION" to produce the result you're looking for.
Ricardo Coto wrote:union isn't the path to take, it scan the table twice
Ricardo Coto wrote:a union isn't the path to take
Ricardo Coto wrote:but it's not sql server, is postgres
Ricardo Coto wrote:Actually the time it took is pretty good, it took a lot of time presenting me de results because i'm using the shell of psql
Ricardo Coto wrote:Query you put before, get me empty categories and takes a lot of time
All things are lawful, but not all things are profitable.
Ricardo Coto wrote:if you notice, below there are some filters in the where clause with the column extracted from the inner queries in the left joins...
Ricardo Coto wrote:Brian:
Adjustment in Funding removing the order by gave one ms of optimization
Adjustment in paid removing last_payment gave me a little bit of time (less tan a ms)
Can't remove the ids you mentioned because they are use to link the joins...
Thanks, i'll go with the next tips...
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |