I have a table where we write to custom values ββsuch as money_spent, money_spent_on_candy and date.
So, the columns in this table (let it be called MoneyTable) will be:
- Userid
- Money_spent
- Money_Spent_On_Candy
- date
My goal is SUM total amount of money_spent - but only for those users where they spent more than 10% of their total money spent on a date range on sweets.
What will this request be?
I know how to select users who have this - and then I can output the data and summarize them manually, but I would like to do this in a single request.
Iβd like a request to get the amount of Expense per user only for users who spent> 10% of their money on sweets.
SELECT UserId, SUM(Money_Spent), SUM(Money_Spent_On_Candy) / SUM(Money_Spent) AS PercentCandySpend FROM MoneyTable WHERE DATE >= '2010-01-01' HAVING PercentCandySpend > 0.1;
source share