Created
May 15, 2017 15:25
-
-
Save shareefhiasat/38d146badf7c90ab7fe38a3c72119181 to your computer and use it in GitHub Desktop.
on my pc it took 60 seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select SQL_CACHE part1.id,part1.event_date,part1.ticket_type,part1.order_id, | |
COALESCE(part1.entry1,part2.entry2),COALESCE(part2.entry2,part1.entry1) from | |
( SELECT `order_item`.id as id,(case when DATE_FORMAT(CONVERT_TZ | |
(`event_date`.`start_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i') != | |
DATE_FORMAT(CONVERT_TZ(`event_date`.`end_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i') | |
then CONCAT(DATE_FORMAT(CONVERT_TZ(`event_date`.`start_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i'), | |
' - ',DATE_FORMAT(CONVERT_TZ(`event_date`.`end_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i')) | |
else DATE_FORMAT(CONVERT_TZ(`event_date`.`start_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i') end) | |
as event_date,`product`.`name` as ticket_type,`order_item`.order_id | |
as order_id,GROUP_CONCAT(DISTINCT(case when submission_entry1.text='' then concat(question1.var,': ') | |
else CONCAT(question1.var, ':', submission_entry1.text) end) order By `submission_entry1`.`question_id` | |
SEPARATOR 0x1D) as entry1 FROM `order_item` | |
INNER JOIN product ON order_item.product_id = product.id | |
INNER JOIN product_form | |
ON product_form.product_id = product.id | |
INNER JOIN event_date_product ON event_date_product.id = order_item.event_date_product_id | |
INNER JOIN event_date ON event_date_product.event_date_id = event_date.id | |
INNER JOIN payment ON payment.id = order_item.payment_id | |
LEFT JOIN submission_entry as submission_entry1 ON order_item.form_submission_id = submission_entry1.form_submission_id | |
LEFT JOIN question as question1 ON question1.id = submission_entry1.question_id | |
WHERE order_item.status = 3.0 /*and event_date.event_id = 4338*/ GROUP BY order_item.id HAVING 1 = 1 and entry1 like '%Johanan%' ORDER BY id DESC ) part1 inner join ( SELECT `order_item`.id as id,(case when DATE_FORMAT(CONVERT_TZ(`event_date`.`start_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i') != DATE_FORMAT(CONVERT_TZ(`event_date`.`end_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i') then CONCAT(DATE_FORMAT(CONVERT_TZ(`event_date`.`start_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i'),' - ',DATE_FORMAT(CONVERT_TZ(`event_date`.`end_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i')) else DATE_FORMAT(CONVERT_TZ(`event_date`.`start_date`,'+0:00','+2:00'),'%d/%m/%Y %H:%i') end) as event_date,`product`.`name` as ticket_type,`order_item`.order_id as order_id,GROUP_CONCAT(DISTINCT(case when submission_entry2.text='' then concat(question2.var,': ') else CONCAT(question2.var, ':', submission_entry2.text) end) order By `submission_entry2`.`question_id` SEPARATOR 0x1D) as entry2 FROM `order_item` INNER JOIN product ON order_item.product_id = product.id INNER JOIN product_form ON product_form.product_id = product.id INNER JOIN event_date_product ON event_date_product.id = order_item.event_date_product_id INNER JOIN event_date ON event_date_product.event_date_id = event_date.id INNER JOIN payment ON payment.id = order_item.payment_id LEFT JOIN submission_entry as submission_entry2 ON submission_entry2.form_submission_id = payment.form_submission_id LEFT JOIN question as question2 ON question2.id = submission_entry2.question_id WHERE /*entry2 like '%Johanan%' and*/ order_item.status = 3.0/* and event_date.event_id = 4338*/ GROUP BY order_item.id HAVING 1 = 1 ORDER BY id DESC ) part2 on part1.id = part2.id LIMIT 0,10 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment