Attempting to Pull Data from Two Separate DB Tables in order to Calculate an Average Percentage Between Two Sums of the Tables via Named Query

SELECT Reason, ( 
	SUM([DTMIN])
	FROM vwIG_DownTimeDetailsByPID
	WHERE Reason = 'Electrical'
  		AND ([Trans Date] BETWEEN '2024-01-01' AND '2024-12-31')
GROUP BY Reason), 
SELECT SUM([SCH MIN]) (
	FROM  vwIG_ProductionSummaryReportByDate
	WHERE ([PROD DATE] BETWEEN '2024-01-01' AND '2024-12-31')
)

Here is the code I currently have written. I am very new to scripting, and I am sure there are obvious errors. I am getting an incorrect syntax error near the keyword 'FROM.' The main thing I wish to accomplish is to get the values of both parts of this code to display in as separate rows when I execute the code in the testing bit of Named Queries. I tried just stacking the code for two separate named queries but I am only getting the display of the first bit of code executed instead of both. If i could please ask for some insight into this issue. Keep in mind, I have not yet written the part of the code that will do the final calculation (that's a problem for future me.)

ERROR:

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'FROM'.

You need to use the UNION syntax to join two result sets.
In addition, both results will have to have the same columns (which should make sense) but your first has two (Reason and the sum) while your second only has one.
While we're at it, you can use the AS syntax to give the SUM column a meaningful name.

SELECT 
    Reason, 
    SUM([DTMIN]) AS Count
FROM vwIG_DownTimeDetailsByPID
WHERE Reason = 'Electrical'
  AND ([Trans Date] BETWEEN '2024-01-01' AND '2024-12-31')
GROUP BY Reason)

UNION 

SELECT 
    "Something goes here" AS Reason,
    SUM([SCH MIN]) AS Count
FROM  vwIG_ProductionSummaryReportByDate
WHERE ([PROD DATE] BETWEEN '2024-01-01' AND '2024-12-31')
1 Like

I need to learn all you know. Thank you once again.