20180820 SELECT SQL_CALC_FOUND_ROWS wpan_posts.ID FROM wpan_posts INNER JOIN wpan_postmeta ON ( wpan_posts.ID = wpan_postmeta.post_id ) INNER JOIN wpan_postmeta AS mt1 ON ( wpan_posts.ID = mt1.post_id ) INNER JOIN wpan_postmeta AS mt2 ON ( wpan_posts.ID = mt2.post_id ) WHERE 1=1 AND ( wpan_postmeta.meta_key = 'data_fine' AND ( ( mt1.meta_key = 'data_inizio' AND CAST(mt1.meta_value AS DATE) <= '20180820' ) AND ( mt2.meta_key = 'data_fine' AND CAST(mt2.meta_value AS DATE) >= '20180820' ) ) ) AND wpan_posts.post_type = 'post' AND (wpan_posts.post_status = 'publish') GROUP BY wpan_posts.ID ORDER BY wpan_postmeta.meta_value ASC LIMIT 0, 200