Slow MYSQL query, when searching for date

Asked

Viewed 21 times

0

I’m doing a date search on mysql, but it gets very slow (more than half a second).

Is there any way to optimize this search to get faster?

Ex: of consultation:

SELECT dt.data,count(d.id) AS downloads, DATE_FORMAT(d.data, '%d/%m/%Y') as dataformat, DATE_FORMAT(d.data, '%d/%m') as dia, DATE_FORMAT(d.data, '%a') as semana FROM sig_datas dt
LEFT JOIN sig_downloads_historicodownload d ON DATE_FORMAT(dt.data, '%d/%m/%Y') = DATE_FORMAT(d.data, '%d/%m/%Y')
WHERE dt.data >= '2020-05-22'
AND dt.data <= '2020-05-25'
GROUP BY dataformat
ORDER BY dt.data ASC
  • Why do you format dates in the merge criteria? Iofc in GROUP BY?

  • to display the total number of downloads per day

  • But his field dt.data is no longer the type date? Or is it like datetime or timestamp?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.