SELECT * from usersannonces WHERE DATEDIFF(NOW(),datefin) > 2 ORDER BY idannonce DESC
SELECT SQL_CALC_FOUND_ROWS
an.*,
ag.telephone,
ag.telephone2,
ag.mobile,
ag.url,
qu.nom AS quartier_nom,
(SELECT COUNT(*) FROM `agences_annonces_recommande` AS anr WHERE anr.ida = an.idag AND anr.idan = an.idan) AS anrecommande,
(SELECT COUNT(*) FROM `agences_page_dediee` AS agd2 WHERE agd2.ida = an.idag) AS agpagedediee2,
(SELECT COUNT(*) FROM `agence` AS agd
LEFT JOIN `forfait` ON agd.`forfait` = `forfait`.`nom`
WHERE agd.id = an.idag AND `forfait`.`page_dediee` = 1) AS agpagedediee
FROM `annonce` AS an
INNER JOIN `agence` AS ag ON an.idag = ag.id
INNER JOIN `quartier` AS qu ON an.quartier = qu.idqu
WHERE 1
AND an.vendu = 'N'
/* AND an.ActivImmo != 'N' */
AND ag.bloque = 'N'
AND ag.id != 7
AND ag.forfait != 'LITE'
AND date >= '2023-11-13'
ORDER BY rand() LIMIT 0,5