group_concat和group by不一起工作

时间:2014-02-11 13:32:08

标签: mysql group-by group-concat

我找到了答案,但我找不到,所以希望你能帮助我。 我正在尝试获取按'vacatureID'和'organisatieID'分组的作业列表。 但我只能让他们中的一个工作。

有人可以提出建议吗?

感谢。

SELECT 

    tblVacature.vacatureNaam, 
    tblVacature.vacatureCode, 
    DATE_FORMAT(tblVacature.vacatureDatumToegevoegd,'%d-%m'), 
    MAX(tblVacature.vacatureSuper), 

    tblOrganisatie.organisatieID, 
    tblOrganisatie.organisatieNaam, 
    tblOrganisatie.organisatieNaamConvert, 

    GROUP_CONCAT(tblSpecialisme.specialismeNaam 
        ORDER BY CASE 
        WHEN specialismeNaam = 'BLABLA' 
        THEN 1 WHEN specialismeNaam = 'BLABLA 2' 
        THEN 2 WHEN specialismeID = '0' 
        THEN 4 ELSE 3 END, specialismeNaam ASC) AS specialismeNamen, 

    GROUP_CONCAT(tblSpecialisme.specialismeNaamConvert 
        ORDER BY CASE 
        WHEN specialismeNaam = 'BLABLA' 
        THEN 1 WHEN specialismeNaam = 'BLABLA 2' 
        THEN 2 WHEN specialismeID = '0' 
        THEN 4 ELSE 3 END, specialismeNaam ASC) AS specialismeNamenConvert 

FROM tblVacature 
LEFT JOIN tblOrganisatie ON (tblVacature.vacatureOrganisatie = tblOrganisatie.organisatieID) 
LEFT JOIN tblSpecialisme ON FIND_IN_SET(tblSpecialisme.specialismeID, REPLACE(tblVacature.vacatureSpecialisme, ' ', ',')) 

WHERE 

    vacatureActive = '1' 
    AND vacatureDatumToegevoegd <= ? 

GROUP BY vacatureID, organisatieID 
ORDER BY MAX(vacatureSuper) DESC, tblVacature.vacatureDatumToegevoegd DESC

0 个答案:

没有答案