Site icon Allure Hosting

How can I merge 2 different queries on a monthly basis

I have 2 queries where I get the results displayed on a monthly basis. These are so perfect for me. Now I would like the two tables to be displayed side by side.

SELECT 

MONTH(begin_ts) AS [Month]     
,SUM(CASE WHEN bmktonr = '7' 
THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '11' 
THEN dauer ELSE reserve1 END) 
AS Prozess_Verfügbarkeit

,SUM(CASE WHEN bmktonr = '1' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '2' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '3' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '4' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '5' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '6' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '7' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '8' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '9' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '10' 
  THEN dauer ELSE reserve1 END) + SUM(CASE WHEN bmktonr = '11' 
  THEN dauer ELSE reserve1 END)
  AS Verfügbarkeit

FROM [hydra1].[hydadm].[v_ereignis]
WHERE masch_nr = 'FIMI1'
AND YEAR(begin_ts)=YEAR(CURRENT_TIMESTAMP)
GROUP BY MONTH(begin_ts)
ORDER BY [Year], [Month]

and this query

SELECT p.masch_nr
,SUM(b.ruest_zeit) as SOLLRüsten
,SUM(b.bearb_zeit) as SOLLProduktion
,SUM(b.ruest_zeit_zuschl) as SOLLZuschlag
,SUM(p.bmk_07) as ISTRüsten
,SUM(p.bmk_11) as ISTProduktion
,MONTH(prot_dat) as Month
FROM [hydra1].[hydadm].[v_auftrag_status] p
JOIN [hydra1].[hydadm].[v_auftrags_bestand] b
ON b.auftrag_nr = p.auftrag_nr
WHERE p.masch_nr = 'GEORG'
AND a_status = 'E'
AND YEAR(prot_dat)=YEAR(CURRENT_TIMESTAMP)

GROUP BY p.masch_nr, MONTH(prot_dat)

 

Exit mobile version