MySQL Forums
Forum List  »  Newbie

Re: Newbie Help! Finding new data within a table comparing to previous records
Posted by: Adam Khan
Date: April 28, 2020 04:42AM

Hi Peter,

You're amazing - that has really helped! I have run these queries against the table and am following the logic.

If I could get a little more direction please!

How do I go about building a loop for the first query result ("This query finds all customer-score pairs from the last 7 days that occurred just once") that uses the output of that query as inputs to loop through the second query?

I assume i'll need to establish some variables to store the outputs and then call them into a loop? This may need to be done outside of MySQL so what do you suggest I use? PHP?

e.g.

select not exists (
select date, customer, score from tbl
where customer='%Input From 1st Query%'
and date < '%Input From 1st Query%'
and date >= '%Input From 1st Query%' - interval 7 day
and score= %Input From 1st Query%
) as new;

Many thanks in advance!

Cheers,
Adam

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.