vuanhtu2811
vuanhtu2811

Reputation: 11

SQL to pick up and calculate SUM

enter image description here

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

Answers (1)

Gordon Linoff
Gordon Linoff

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

Related Questions