Created
October 7, 2016 12:34
-
-
Save Hotfirenet/a63804b14c6ed28f511c46eac33339df to your computer and use it in GitHub Desktop.
Cette requete prestashop permet de lister les client par groupes en ayant les groupes en colonne. j'ai utilisé un système de pivot pour mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET group_concat_max_len = 18446744073709551615; | |
SET @COLUMNS = NULL; | |
SELECT GROUP_CONCAT( | |
DISTINCT CONCAT( | |
'GROUP_CONCAT(IF(C.id_group = "', | |
C.id_group , | |
'", "X", NULL)) AS "', | |
C.name, | |
'"' | |
) | |
) INTO @COLUMNS | |
FROM ps_group_lang C | |
WHERE id_lang=1; | |
SET @SQL = CONCAT( | |
'SELECT | |
A.company, | |
A.firstname, | |
A.lastname, | |
A.email, | |
A.id_customer, | |
A.atoosync_code_client AS codeSAGE, | |
',@COLUMNS,' | |
FROM ps_customer A | |
INNER JOIN ps_customer_group B ON B.id_customer = A.id_customer | |
INNER JOIN ps_group_lang C ON C.id_group = B.id_group | |
WHERE C.id_lang = 1 | |
GROUP BY A.email | |
ORDER BY A.company | |
' | |
); | |
PREPARE stmt FROM @SQL; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment