i want to get users from table that have atleast total of 20,000 $ buy in 50 days.
for example -> a user may have bought a service 200 days ago with amount of 5,000 and bought another service with amount of 10,000 180 days ago and , another service he bought was 160 days ago with amount of 5,000.
so the time between these are less than 50 and total amount is atleast 20,000 then he is the user that should be returned.
another example -> a user bought a service 80 days ago with amount of 10,000 and another service with amount of 5,000 in 40 days ago and, last service was 5,000 in 20 days ago
so the amount is 20,000 but he couldn't fill it in 50 days because his last buy was 60 days after the first on , so he can't be the user we want.
however if this user bought another service in 10 days ago with amount of 10,000 then he can be the user because his second , third and fourth buy was in 50 days and had atleast 20,000 .
i explained as much as i could.
the point is that the date can be a day of 2 years ago and maybe the user filled 20,000 with 5 product .
i'm attaching my table picture here so if u write query for this table it would be very good .
its just 1 table.
the total column in my table is the price for 1 specific buy.
and the column for date is date column.
EDIT
this is the query i got , its just getting total and my problem is with time .
SELECT invoice.userid, Sum(invoice.total) AS totsam
FROM invoice
GROUP BY table.userid
HAVING totsam > 20000
something along the lines of
SELECT * FROM table WHERE days < 50 AND totalAmount > 20000
SELECT *
FROM invoice_table
WHERE
(DATEDIFF(CURDATE(),invoice_table.date)<50
AND SUM(total)>20000)