mysql - Joining two select queries but one is grouped -
i have (entrance)ticket table ticket_code, timestamp_processed , event code.
i.e.:
ticket_code event timestamp_processed --------------------------------------------------------- 44185909829105549 ticket_accepted 1434636748 now want count occurrence of every event = 'ticket_accepted' until end of specified time frame.
i use query:
select ticket_code, count(ticket_code) count rest_history timestamp_processed <= :endtime , event = 'ticket_accepted' group ticket_code now want count , ticket_codes of specific time range starttime.
here query ticket_codes in specific time range:
select ticket_code rest_history timestamp_processed >= :starttime , timestamp_processed <= :endtime , event = 'ticket_accepted' now want inner join both queries or build 1 using subselect, can't right solution. can give me hint?
update:
in end want group ticket_code individual count of each occurrence of every ticket_code event = 'ticket_accepted' in specific timeframe count value should include occurrences until endframe , not since "starttime".
i.e:
[ticket_code] => 1434636748 [count] => 3 [ticket_code] => 3434636745 [count] => 1 [ticket_code] => 2434636546 [count] => 10
i think work:
select t1.ticket_code, t1.count (select ticket_code, max(timestamp_processed) lasttime, count(ticket_code) count rest_history timestamp_processed <= :endtime , event = 'ticket_accepted' group ticket_code) t1 t1.lasttime >= :starttime by using max(timestamp), making sure ticket timestamp_processed >= startime gets included greatest timestamp in subquery, passes test of outer query.
Comments
Post a Comment