我在表中有数据
我想要上个月的消费和最近三个月的消费
例如基于阅读
我试过这个:
SELECT tbl.CustomerID
,tbl.CustomerName
,tbl2.Last3Months
,tbl.LastMonth
FROM (
SELECT events.event_item_id CustomerID
,items.item_name CustomerName
,MAX(events.event_additional_info) maxR
,MIN(events.event_additional_info) minR
,(MAX(events.event_additional_info) - MIN(events.event_additional_info)) AS LastMonth
FROM events
INNER JOIN items ON events.event_item_id = items.item_id
WHERE (events.event_additional_info <> '0.000000')
AND (
events.event_timestamp BETWEEN '08-MAY-15 12:00:00 AM'
AND '08-Jun-15 6:21:59 PM'
)
GROUP BY events.event_item_id
,items.item_name
) tbl
,(
SELECT events.event_item_id CustomerID
,items.item_name CustomerName
,MAX(events.event_additional_info) maxR
,MIN(events.event_additional_info) minR
,(MAX(events.event_additional_info) - MIN(events.event_additional_info)) AS Last3Months
FROM events
INNER JOIN items ON events.event_item_id = items.item_id
WHERE (events.event_additional_info <> '0.000000')
AND (
events.event_timestamp BETWEEN '08-MAR-15 12:00:00 AM'
AND '08-Jun-15 6:21:59 PM'
)
GROUP BY events.event_item_id
,items.item_name
) tbl2
WHERE tbl2.CustomerID = tbl.CustomerID