Using aggregation in case statements
I have a data set of sales where a sale is either a "new sale" or an "add sale". This value is stored in `calcSaleType`. I would like to graph the ratio of new sales to add sales over time but keep turning up null values.
The value of a sale is stored in `total_cost`.
I've tried the following with no luck:
(case when `sale_type`='new sale' then sum(`total_cost`) end) / (case when `sale_type`='add sale' then sum(`total_cost`) end)
Even when I try simply graphing the following, I get mostly null values even though every row contains a `calcSaleType` value. What am I missing here?