CodePudding user response:
Can use condition exists, also can be associated withselect count (1) the from (
Select distinct firs. Buyer_id from table1 as firs -- the first day
Where the exists (
Select the from 1
Table1 as SEC - the second day
Where DATEDIFF (DAY, firs, SEC)=1
And firs. Buyer_id=SEC. Buyer_id
And firs. Item_id & lt;> The SEC. Item_id -- -- the first and second day buy goods different
And the exists (
Select the from 1
Table1 as tree - the third day
Where DATEDIFF (DAY, firs. Buy_date, tree. Buy_date)=2
And firs. Buyer_id=tree. Buyer_id
And firs. Item_id & lt;> Tree. Item_id -- -- the first day and on the third day buy goods different
)) as a