0
我有兩個select語句。在過去的60秒內獲得記錄的電壓數據的列表(如果有的話)和相關的房間名稱,並且在過去的5分鐘內獲得記錄的電弧事件數據的列表(如果有的話)。我試圖將電弧計數數據作爲新列附加到電壓數據表中。我無法弄清楚如何做到這一點。SQL union/join/intersect多個select語句
請注意,對於電壓數據表中給定的腔室名稱,可能有也可能沒有電弧計數行。如果沒有行,我想將弧計數列值設置爲零。
有關如何完成此任何想法?
電壓數據:
SELECT DISTINCT dbo.CoatingChambers.Name,
AVG(dbo.CoatingGridVoltage_Data.ChanA_DCVolts) AS ChanADC,
AVG(dbo.CoatingGridVoltage_Data.ChanB_DCVolts) AS ChanBDC,
AVG(dbo.CoatingGridVoltage_Data.ChanA_RFVolts) AS ChanARF,
AVG(dbo.CoatingGridVoltage_Data.ChanB_RFVolts) AS ChanBRF FROM
dbo.CoatingGridVoltage_Data LEFT OUTER JOIN dbo.CoatingChambers ON
dbo.CoatingGridVoltage_Data.CoatingChambersID =
dbo.CoatingChambers.CoatingChambersID WHERE
(dbo.CoatingGridVoltage_Data.DT > DATEADD(second, - 60,
SYSUTCDATETIME())) GROUP BY dbo.CoatingChambers.Name
返回
Name | ChanADC | ChanBDC | ChanARF | ChanBRF
-----+-------------------+--------------------+---------------------+------------------
OX2 | 2.9099999666214 | -0.485000004371007 | 0.344801843166351 | 0.49748428662618
S2 | 0.100000001490116 | -0.800000016887983 | 0.00690172302226226 | 0.700591623783112
S3 | 4.25666658083598 | 0.5 | 0.96554297208786 | 0.134956782062848
弧伯爵表:
SELECT CoatingChambers.Name,
SUM(ArcCount) as ArcCount
FROM CoatingChambers
LEFT JOIN CoatingArc_Data
ON dbo.[CoatingArc_Data].CoatingChambersID = dbo.CoatingChambers.CoatingChambersID
where EventDT > DATEADD(mi,-5, GETDATE())
Group by Name
返回
Name | ArcCount
-----+---------
L1 | 283
L4 | 0
L6 | 1
S2 | 55
要清楚,我想這個表(添加弧數列),鑑於上面的兩個表:
Name | ChanADC | ChanBDC | ChanARF | ChanBRF | ArcCount
-----+-------------------+--------------------+---------------------+-------------------+---------
OX2 | 2.9099999666214 | -0.485000004371007 | 0.344801843166351 | 0.49748428662618 | 0
S2 | 0.100000001490116 | -0.800000016887983 | 0.00690172302226226 | 0.700591623783112 | 55
S3 | 4.25666658083598 | 0.5 | 0.96554297208786 | 0.134956782062848 | 0
太棒了,謝謝你的時間。 isnull()對我來說是新的。當我嘗試加入虛擬桌面時,我不知何故失敗... –
很高興幫助:-) – Clay