0
我有2個表:客戶表和活動表。我試圖找出有多少客戶有2個具體的活動。例如,有多少客戶被購買併到達分行。 (我在活動錶行的一舉一動,客戶做到了。)這是查詢:在子查詢和主查詢日期之前
SELECT COUNT(*) as total FROM activity
WHERE activity = 'arrived' AND
customerid IN
(SELECT DISTINCT(customerid) FROM activity
WHERE activity = 'bought')
,但我需要知道買了多少後,他們arrvied,因爲有從網站上購買,比例在1年後抵達分行。所以我只想要那些到達並比購買的客戶。 我想這:
SELECT COUNT(*) as total, daten as odaten FROM activity
WHERE activity = 'arrived' AND
customerid IN
(SELECT DISTINCT(customerid), daten as tdaten FROM activity
WHERE activity = 'bought') HAVING odaten < tdaten
,但其沒有工作..任何想法?
謝謝!是工作! – 2014-12-19 16:22:27