我正在尝试在 Wonderware 中的表中查询某些数据。我知道查询的“a”部分中有一些数据,其 TagName 等于“Weightdata2.uiID”。但是“b”部分没有匹配的数据,因此查询返回空数据集。但是,如果那里没有匹配的数据,我想在 uiWater 列中获取 'a' 部分和 'b' 的数据,其中 NULL 或零。
这是我的查询:
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
set @StartDate = '2018-09-18 08:00:00.000'
set @EndDate = '2018-09-18 09:00:00.000'
SELECT a.Value as uiID, b.value as uiWater, cast(a.datetime as datetime2(0))
as dtCreated, 2 as Weightdata
FROM [INSQL].[Runtime].[dbo].[History] a
JOIN [INSQL].[Runtime].[dbo].[History] b ON a.datetime=b.datetime
WHERE a.TagName IN ('Weightdata2.uiID') and a.datetime>=@StartDate and
a.datetime<=@EndDate and a.Value!=0
and b.TagName IN ('Weightdata2.uiWater') and b.datetime>=@StartDate and
b.datetime<=@EndDate