Reputation: 11
I have 2 tables:
How to calculate the total sales revenue of each Username within 30 days from Join date? Thank you very much in advance!!!
Upvotes: 0
Views: 34
Reputation: 1270593
You can use join
and aggregation:
select u.username, sum(revenue)
from users u left join
orders o
on o.username = u.username and
o.salesdate < u.joindate + interval 30 day
group by u.username
Upvotes: 1