Home > database >  Please help have a look at the SQL problems
Please help have a look at the SQL problems

Time:10-10

Every great god meets the novice don't know how to solve a problem, trouble to help have a look at the last question, thank!

CodePudding user response:

Can use condition exists, also can be associated with
 select 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
  • Related