user_id、purchase sku、およびイベントtime_createdを格納するテーブル(user_tracking)があります。ユーザーが購入に戻るたびに、元のuser_idが新しいタイムスタンプで参照されます。
User_ID Sku Time_Created
1 1234 2012-10-01 01:00:00
2 2345 2012-10-02 02:00:00
3 6789 2012-10-02 01:00:00
2 5432 2012-10-04 04:00:00
返品のお客様の使用状況を測定したいのですが、最初の購入から7〜60日以内に返品したお客様のみを対象としています。現在、私のクエリは次のようになっています。
SELECT
total_purchases.user_id as user_1_id,
total_purchases.time_created as time_1_created,
total_purchases.total_purchases as total_original_purchases,
total_return.user_id as user_2_id,
total_return.time_created as time_2_created,
total_return.total_return_purchases as total_return_purchases
FROM (SELECT
user_tracking.user_id as user_id,
user_tracking.time_created as time_created,
COUNT(DISTINCT user_tracking.sku) as total_purchases
FROM user_tracking
WHERE user_tracking.time_created BETWEEN "2012-10-01 00:00:00"
AND "2012-10-15 00:00:00") AS total_purchases
LEFT JOIN (SELECT
user_tracking.user_id as user_id,
user_tracking.time_created as time_created,
COUNT(DISTINCT user_tracking.sku) as total_return_purchases
FROM user_tracking
WHERE user_tracking.time_created BETWEEN "2012-10-01 00:00:00"
and "2012-12-15 00:00:00") AS total_return
ON total_purchases.user_id = total_return.user_id
元のユーザーとの7〜60日以内の購入のみを測定していることを確認するにはどうすればよいですか?