I have a large DB of SALES_ORDERS
, that I need to determine the % each SELLING_AGENT
had in the ORDER
.
Learning postgresql, and this is just a sample, of ~500k rows of data. Each ORDER#
could be composed of dozens of SALE_ITEM
s (but only composed of 'SALE_ITEM_1'
and 'SALE_ITEM_2'
).
I thought I could try doing a SUM SELECT something like this:
SELECT (SUM(sale_item_1)+sum(sale_item_2)) as total_person_sale
FROM SALES_ORDER
WHERE orderNumber LIKE orderNumber
GROUP by SELLING_AGENT
But clearly I'm not grasping the WHERE statement use to count similar
The hope is to fill out the final column, like this: selling agent:
selling agent: Order# Sale_item_1 Sale_item_2 %_of_TOTAL_order
jim abc $1.00 $2.00 14.29%
steve abc $3.00 $4.00 33.33%
carl abc $5.00 $6.00 52.38%
carl def $7.00 $8.00 31.25%
steve def $9.00 $9.00 37.50%
jim def $8.00 $7.00 31.25%
steve ghi $6.00 $5.00 61.11%
patty ghi $4.00 $3.00 38.89%