I have a view named transactions_per_day
I am trying to get SQL to return when 2 or more transactions for the customer add up to over 10,000 for a variable time period.
I've set the @startdate and @enddate variables so that my time period could be a week, two weeks, or a month.
I've also set the @maxamount variable to 10000.
I was able to get the sums of all the transactions grouped by customer_id, and apply an IF statement to test is the sum of the amounts are greater than the @maxamount variable, but I don't know how to incorporate the date range variables in the SQL query.
Ideally, I would like to only see the customers and transactions that have summed to surpassed the @maxamount threshold during the variable time range set by @startdate and @enddate.
customer_id | Sum of transactions during variable period | number of days during variable period
Thanks for any help, I appreciate it.