Я использую MySQL 5.6 и у меня проблема с результатами запроса, используя GROUP BY
и LIMIT + OFFEST
. Эти результаты не согласуются с результатами без OFFSET
. Зачем ? И в чем решение?
Этот запрос (без OFFSET
и без GROUP BY
) дал мне 10 результатов:
SELECT sp.couleur, sp.nom, d.degre_urgence
FROM demande_interservices AS d
LEFT JOIN demande_interservices_a_valider AS dv ON d.id = dv.demande_interservices_id
LEFT JOIN demande_interservices_affectee_a_sous_pole AS d_aff ON d.id = d_aff.demande_interservices_id
LEFT JOIN sous_pole AS sp ON d_aff.sous_pole_id = sp.id
WHERE d.pole_sollicite_id = (SELECT pole_id FROM utilisateur WHERE id = 38)
AND (d.statut_id = 1 OR d.statut_id = 2)
AND dv.demande_interservices_id IS NULL
ORDER BY d.degre_urgence DESC
LIMIT 10
Результаты:
couleur degre_urgence nom
_______________________________
#cd423a 5 Communication
#cd423a 5 Communication
#ff3ebb 5 Assistante DGS
#925210 5 Police Urbanisme
#000000 5 informatique RGPD
#cd423a 5 Communication
#ff3ebb 5 Assistante DGS
#e2c63d 5 Urbanisme - Marchés Publics
#ff3ebb 5 Assistante DGS
#925210 4 Police Urbanisme
Тот же запрос с GROUP BY
;
SELECT sp.couleur, sp.nom, d.degre_urgence
FROM demande_interservices AS d
LEFT JOIN demande_interservices_a_valider AS dv ON d.id = dv.demande_interservices_id
LEFT JOIN demande_interservices_affectee_a_sous_pole AS d_aff ON d.id = d_aff.demande_interservices_id
LEFT JOIN sous_pole AS sp ON d_aff.sous_pole_id = sp.id
WHERE d.pole_sollicite_id = (SELECT pole_id FROM utilisateur WHERE id = 38)
AND (d.statut_id = 1 OR d.statut_id = 2)
AND dv.demande_interservices_id IS NULL
GROUP BY nom
ORDER BY d.degre_urgence DESC
LIMIT 10
Результаты:
couleur degre_urgence nom
_______________________________
#e2c63d 5 Urbanisme - Marchés Publics
#000000 5 informatique RGPD
#925210 5 Police Urbanisme
#fff000 2 Accueil
#7bd026 1 ASVP
#cd423a 1 Communication
#ff3ebb 1 Assistante DGS
Но я ожидал таких результатов:
couleur degre_urgence nom
_______________________________
#cd423a 5 Communication
#ff3ebb 5 Assistante DGS
#925210 5 Police Urbanisme
#000000 5 informatique RGPD
#e2c63d 5 Urbanisme - Marchés Publics