異なるデータを照会する必要がある 2 つのテーブルがあります。共通のリンクは datetime 列です。クエリをマージしようとしましたが、さまざまなエラーが発生し続けます...
最後のクエリは次のようになります。date, Peak Power each Day, KWHOpenHrs, KWHClosedTotal
どんな助けでも大歓迎です。
2つのテーブルは以下です
Peak KVA
テーブル
Date | Power_Apparent_Total
クエリ:
SELECT
CAST(t.HD as DATE), MAX(t.Power_Apparent_Total) as 'Peak Power Each Day'
FROM [Peak kVA] t
GROUP BY CAST(t.HD AS DATE)
Daily Consumption
Date | KWH Open | KWH ClosedandOccupied | KWH ClosedandnotOccupied
クエリ:
select date,
max(value) kWhOpenHrs,
sum(case when col in ('zkWhClsedAndOccupied', 'zkWhClsedAndNotOccupied') then value end) kWhClsedTotal
from
(
select date, 'zkWhOpenHrs' as col, kWhOpenHours as value
from dbo.tblDailyPowerConsumption
union all
select date, 'zkWhClsedAndNotOccupied' as col, kWhClosedAndNotOccupied as value
from dbo.tblDailyPowerConsumption
union all
select date, 'zkWhClsedAndOccupied' as col, kWhClosedAndOccupied as value
from dbo.tblDailyPowerConsumption
) src
WHERE MONTH(date) = '12'
group by date