I'm having trouble finding the totals when it comes to 'within 1 & 2 months of the signup date'. I would love some help and some feedback on my current code. No errors, just not sure how to address the question
The question is: Find the average revenue per member that signed up in January within 1 month and 2 months of their signup date
The data table is:
Table 1: Memberships
member_id (PK) int signup_date datetime join_country varchar(2) email varchar cancellation_date date expiry_date date
Table 2: Transactions
transaction_id (PK) int member_id int transaction_date datetime transaction_type_ID int product_id int transaction_amount float
Current code:
SELECT AVG (t.transaction_amount) AS AVG_REV,
COUNT(m.member_id) AS Member_ID
FROM transactions AS t
INNER JOIN memberships AS m
ON m.member_id = t.member_id
WHERE m.signup_date BETWEEN '2018-01-01' AND '2018-01-31'
GROUP BY m.member_id
;
This sounds like you want two numbers: The average 1 month revenue after signup and the average two month revenue after signup. There really isn't an "average revenue" for each
member_id
. There is a total revenue for each member, and then the average across all members.I think the best approach is to aggregate the revenue by member and then take the averages. By member, the total revenue in these periods is:
Then, aggregate again for the overall averages: