Expression are evaluated in the column order in the select clause.
This is the same for the where clause. An advice is to test first the expression that get more chance to return false at the head of the where conditions :
- SET @BRAND=0;
- SET @ct=0;
- SELECT
- *
- FROM
- (SELECT
- IF(@BRAND<>id_BRAND,@ct:=0 ,@ct:=@ct ) ,
- @ct:=@ct+1 AS ct,
- @BRAND:=id_BRAND,
- t2.*
- FROM
- (SELECT
- st.ID_BRAND,
- st.ID_MODEL,
- SUM(COMPTE) AS total,
- AVG(totalm)
- FROM
- STAT st JOIN
- (SELECT
- ID_BRAND,
- SUM(COMPTE) AS totalm
- FROM
- STAT
- GROUP BY
- ID_BRAND
- ORDER BY
- totalm DESC
- LIMIT 5
- ) as t USING( ID_BRAND)
- GROUP BY
- st.ID_BRAND,
- st.ID_MODEL
- ORDER BY
- st.ID_BRAND,
- total DESC
- ) AS t2
- ) AS t3
- WHERE
- ct <=5
Aucun commentaire:
Enregistrer un commentaire