1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| SELECT DISTINCT `STTCAT_MTLib` AS rep_categ
,(CASE WHEN `TPIT_NatId` = 31 THEN COUNT(`TPIT_NatId`) ELSE 0 END) AS rep_nb_hg
,(CASE WHEN `TPIT_LocId` = 3 THEN COUNT(`TPIT_NatId`) ELSE 0 END) AS rep_nb_sic
,(CASE WHEN `TPIT_NatId` IN (9,12,32,46,65,81,82) THEN COUNT(`TPIT_NatId`) ELSE 0 END) AS rep_nb_ad
FROM `t_pitemp`
LEFT JOIN `st_categ` ON `STTCAT_Id` = MID(`TPIT_ProfilId`,2,1) AND `STTCAT_Used` = 1
LEFT JOIN `st_sgeoloc` ON `STSGL_Id` = `TPIT_LocId` AND `STSGL_Used` = 1
LEFT JOIN `st_ca` ON `STCA_Id` = `STSGL_CaId` AND `STCA_Used` = 1
WHERE `TPIT_StateId` IN (2,3,4)
AND `TPIT_Used` = 1
GROUP BY `STTCAT_MTLib`
UNION ALL
SELECT 'tot'--dernière ligne de total
,(CASE WHEN MID(`TPIT_ProfilId`,1,1) = 1 THEN COUNT(`TPIT_ProfilId`) ELSE 0 END) AS rep_nb_ind
,(CASE WHEN MID(`TPIT_ProfilId`,1,1) = 2 THEN COUNT(`TPIT_ProfilId`) ELSE 0 END) AS rep_nb_col
,SUM(0) + SUM(1) as rep_sum
FROM `t_pitemp`
LEFT JOIN `st_categ` ON `STTCAT_Id` = MID(`TPIT_ProfilId`,2,1) AND `STTCAT_Used` = 1
WHERE `TPIT_StateId` IN (2,3,4)
AND `TPIT_Used` = 1 |
Partager