//$db->prepare("SELECT r.label,an.formacode,ROUND(AVG(an.noteglobale)) AS notemoyenne,COUNT(an.orga_id) AS nbavis
// FROM anotea an
// INNER JOIN reference r ON r.type=4 AND r.status=1 AND r.level=0 AND FUNC_EXTRADATA('fm',r.extradata,'')=SUBSTRING(an.formacode,1,3)
// WHERE an.status='ACTIVE' AND an.orga_id=%rd
// GROUP BY FUNC_EXTRADATA('fm',r.extradata,'')",
// $orga_id);
if(0)
$db->prepare("
SELECT r.label,r.labelslug,FUNC_EXTRADATA('fm',r.extradata,'') AS formacode,r.path AS formapath,ROUND(AVG(an.noteglobale)) AS notemoyenne,COUNT(DISTINCT an.id) AS nbavis,COUNT(DISTINCT s.ad_id,s.location) AS nbannonces
FROM reference r
INNER JOIN sphad s ON s.query=CONCAT('@formacode ',FUNC_EXTRADATA('fm',r.extradata,''),'*;mode=extended2;maxmatches=200000;limit=10000;filter=orgaid,%rd;')
LEFT OUTER JOIN anotea an ON SUBSTRING(an.formacode,1,3)=FUNC_EXTRADATA('fm',r.extradata,'') AND an.status='ACTIVE' AND an.orga_id=%rd
WHERE r.type=4 AND r.status=1 AND r.level=0
GROUP BY FUNC_EXTRADATA('fm',r.extradata,'')",
$orga_id,$orga_id);
if(0)
$db->prepare("
SELECT sql_no_cache r.label,r.labelslug,FUNC_EXTRADATA('fm',r.extradata,'') AS formacode,r.path AS formapath,ROUND(AVG(an.noteglobale)) AS notemoyenne,COUNT(DISTINCT an.id) AS nbavis,s._sph_count AS nbannonces
FROM reference r
INNER JOIN sphad s ON s.query=CONCAT('@formacode ',FUNC_EXTRADATA('fm',r.extradata,''),'*;mode=extended2;maxmatches=1;groupby=attr:groupbyanotea;limit=10000;filter=orgaid,2345;')
LEFT OUTER JOIN anotea an ON SUBSTRING(an.formacode,1,3)=FUNC_EXTRADATA('fm',r.extradata,'') AND an.status='ACTIVE' AND an.orga_id=2345
WHERE r.type=4 AND r.status=1 AND r.level=0
GROUP BY r.label,r.labelslug,FUNC_EXTRADATA('fm',r.extradata,'')
ORDER BY formacode
",$orga_id,$orga_id);
if(1)
$db->prepare("
SELECT SQL_NO_CACHE
r.label,
r.labelslug,
s.racineformacodeprincipal AS formacode,
r.path AS formapath,
ROUND(AVG(an.noteglobale)) AS notemoyenne,
COUNT(an.id) AS nbavis,
s.nbannonces
FROM
(
SELECT s.orgaid,s.racineformacodeprincipal,s._sph_count AS nbannonces
FROM sphad s
WHERE s.query=';mode=ext2;groupby=attr:racineformacodeprincipal;limit=10000;filter=orgaid,%rd'
) AS s
INNER JOIN reference r ON r.type=4 AND r.status=1 AND r.level=0 AND FUNC_EXTRADATA('fm',r.extradata,'')=s.racineformacodeprincipal
LEFT OUTER JOIN anotea an ON SUBSTRING(an.formacode,1,3)=s.racineformacodeprincipal AND an.status='ACTIVE' AND an.orga_id=s.orgaid