使用concat和内部联接进行sql查询优化

时间:2018-07-31 05:54:09

标签: mysql sql query-optimization

我正在运行此查询,它需要很长时间才能运行超过400秒。我在票务表中只有2万条记录。我想最小化几秒钟

select A.ticket_id, A.ticket_number,
       P.ticket_id, P.ticket_number,
       count(P.ticket_number) as cnt
   from       ticket A
   inner join ticket P  on A.ticket_id != P.ticket_id
where
((A.ticket_number like concat("%", lpad(P.pick1,2,0), "%"))
(A.ticket_number like concat("%", lpad(P.pick2,2,0), "%"))
(A.ticket_number like concat("%", lpad(P.pick3,2,0), "%"))
(A.ticket_number like concat("%", lpad(P.pick4,2,0), "%"))
(A.ticket_number like concat("%", lpad(P.pick5,2,0), "%"))
(A.ticket_number like concat("%", lpad(P.pick6,2,0), "%")) > 3)
group by A.ticket_id
having cnt > 11;

有什么办法可以最小化该查询的执行?

0 个答案:

没有答案