Bonjour a tous,

je cherche a joindre deux requetes CROSSTAB (extension tablefunc de Postgresql).
Cela fonctionne mais pas a 100% comme je le veux ...

Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(SELECT * 
FROM crosstab( 
  'select to_date(datum, ''DD-MM-YYYY''), code, teil 
   from vermzteildate where code in 
   (''SBK'',''SNK'',''SHK'', ''SMK'',''Leerrohr'',''SXX'',''NXX'',''EGL'') order by 1,2', 
   $$VALUES 
   ('SBK'::text), ('SNK'::text), ('SHK'::text), ('SMK'::text), ('Leerrohr'::text), ('SXX'::text), ('NXX'::text), ('EGL'::text)$$) 
AS pivot_test ( datum date, 
     SBK_t bigint, SNK_t bigint, SHK_t bigint,  SMK_t bigint,  Leerrohr_t bigint,  SXX_t bigint,  NXX_t bigint,  EGL_t bigint) order by datum)
 
	 union all
 
(SELECT * 
FROM crosstab( 
  'select to_date(datum, ''DD-MM-YYYY''), code, laenge 
   from vermzkabeldate where code in 
   (''SBK'',''SNK'',''SHK'', ''SMK'',''Leerrohr'',''NMR'',''NRB'',''EGL'') order by 1,2', 
   $$VALUES 
   ('SBK'::text), ('SNK'::text), ('SHK'::text), ('SMK'::text), ('Leerrohr'::text), ('NMR'::text), ('NRB'::text), ('EGL'::text)$$) 
AS pivot_test ( datum date, 
     SBK_m numeric, SNK_m numeric, SHK_m numeric,  SMK_m numeric,  Leerrohr_m numeric,  NMR_m numeric,  NRB_m numeric,  EGL_m numeric) order by datum);
et voici la sortie:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
datum	sbk_t	snk_t	shk_t	smk_t	leerrohr_t	sxx_t	nxx_t	egl_t
2018-02-14	 	 	 	 	4	2	 	
2018-02-19	 	 	1	8	8	 	6	
2018-03-07	 	1	 	2	 	 	1	
2018-02-14	 	 	 	15.87	47.40	 	15.86	
2018-02-19	 	 	 	49.72	44.36	 	78.11	
2018-03-07	 	51.75
Je cherche grouper sur le champs datum et que les champs du deuxieme Pivot soit prisent en compte.
Est-ce que quelqu'un aurait une idée?