各位大神們,初學者遇上一個問題不知道怎么解決,麻煩幫忙看一下最后一個問題,謝謝啦
uj5u.com熱心網友回復:
可以用條件exists,也可以用關聯實作select count(1) from(
select distinct firs.buyer_id from table1 as firs--第一天
where exists(
select 1 from
table1 as sec --第二天
where DATEDIFF(DAY,firs,sec)=1
and firs.buyer_id=sec.buyer_id
and firs.item_id<>sec.item_id --第一天和第二天購買商品不同
and exists(
select 1 from
table1 as tree --第三天
where DATEDIFF(DAY,firs.buy_date,tree.buy_date)=2
and firs.buyer_id=tree.buyer_id
and firs.item_id<>tree.item_id --第一天和第三天購買商品不同
)) as a
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/13385.html
標籤:MySQL
