#
#	ITSV GmbH
#	CCDB - Command and Control Database
#
#	FILE:		dquermfile_DCRESDATA.txt
#	DESCRIPTION:	DQUERY definition for CCDB DQUERY "DCRESDATA"
#
@querytitle	Zur Auswertung verfügbare Datenbestände für RZ-Verbrauchsdaten
@querydescription	Das Query DCRESDATA zeigt an, welche Datenbestände zur Auswertung von RZ-Verbrauchsdaten zur Verfügung stehen (In der Tabelle CCDCRESA)
@group	DCRES
@title	Wochen-Datenbestände, die für Auswertungen des Verbrauchs von RZ-Ressourcen zur Verfügung stehen
@sql	select JAHR as "Jahr", count(KW) as "Anzahl Wochen", count(IN_LADEBESTAENDEN) as "Anzahl Ladebestände", 
		       min(KW) as "Erste Kalenderwoche", max(KW) as "Letzte Kalenderwoche",
		       min(IN_LADEBESTAENDEN) as "Erster Ladebestand", max(IN_LADEBESTAENDEN) as "Letzter Ladebestand"
		  from (select JAHR, KW, wm_concat(distinct LOADNAME) as IN_LADEBESTAENDEN, 
		               (select wm_concat(count(*)) from CCDCRESA d where d.JAHR=dcr.JAHR and d.KW=dcr.KW group by d.JAHR, d.KW, d.LOADNAME) as LADEBESTANDGROESSEN 
		          from CCDCRESA dcr 
		         group by JAHR, KW 
		         order by JAHR, KW asc) 
		 group by JAHR
		 order by JAHR asc
@OLD_sql_mysql	select JAHR as "Jahr", count(KW) as "Anzahl Wochen", count(IN_LADEBESTAENDEN) as "Anzahl Ladebestände", 
		       min(KW) as "Erste Kalenderwoche", max(KW) as "Letzte Kalenderwoche",
		       min(IN_LADEBESTAENDEN) as "Erster Ladebestand", max(IN_LADEBESTAENDEN) as "Letzter Ladebestand"
		  from (select JAHR, KW, GROUP_CONCAT(distinct LOADNAME) as IN_LADEBESTAENDEN, 
		                            (select GROUP_CONCAT(ls.LOADSIZE) 
		                                from CCVDCLOADSIZES ls where ls.JAHR=dcr.JAHR and ls.KW=dcr.KW 
		                               group by ls.JAHR, ls.KW) as LADEBESTANDGROESSEN 
		          from CCDCRESA dcr 
		         group by JAHR, KW 
		         order by JAHR, KW asc) gd 
		 group by JAHR
		 order by JAHR asc
@sql_mysql	select	JAHR as "Jahr", count(KW) as "Anzahl Wochen", 
					count(IN_LADEBESTAENDEN) as "Anzahl Ladebestände", 
					min(KW) as "Erste Kalenderwoche", 
					max(KW) as "Letzte Kalenderwoche",
					min(IN_LADEBESTAENDEN) as "Erster Ladebestand", 
					max(IN_LADEBESTAENDEN) as "Letzter Ladebestand"
			  from (select JAHR, 
					KW, 
					GROUP_CONCAT(distinct LOADNAME) as IN_LADEBESTAENDEN, 
					'WEISSNICHT' as LADEBESTANDSGROESSEN 
					 from CCDCRESA dcr 
					group by JAHR, KW 
					order by JAHR, KW asc) ldsz 
			group by JAHR
			order by JAHR asc

