我编写了一个查询来从表中的一列获取值,并根据 where 子句在数据网格视图的两列中表示它们。以下是查询,
Select ElectricityMachinePanelDetails.MachineDescription AS "Machine Name",
case when (ReadingCategoryID = 'RC001' AND ReadingTypesDetails.ReadingTypeID = 'RT001')
then ReadingValue
end as [Last Day Meter Reading],
case when (ReadingCategoryID = 'RC001' AND ReadingTypesDetails.ReadingTypeID = 'RT002')
then ReadingValue
end as [Current Day Meter Reading]
from ElectricityDailyMeterReadingDetails
INNER JOIN ElectricityMachinePanelDetails on ElectricityMachinePanelDetails.MachinePanelID = ElectricityDailyMeterReadingDetails.MachinePanelID
INNER JOIN ReadingTypesDetails ON ElectricityDailyMeterReadingDetails.ReadingTypeID = ReadingTypesDetails.ReadingTypeID
WHERE ReadingCategoryID = 'RC001' AND ReadingTypesDetails.ReadingTypeID = 'RT001'
基于读取类型 ID,列的值会发生变化..例如
如果我使用ReadingTypesDetails.ReadingTypeID = 'RT002'
Machine Name Last Day Meter Reading Current Day Meter Reading
Transformer 01 NULL 60.000000
Transformer 02 NULL 60.000000
Transformer 03 NULL 80.000000
如果我使用ReadingTypesDetails.ReadingTypeID = 'RT001'
Machine Name Last Day Meter Reading Current Day Meter Reading
Transformer 01 52.000000 NULL
Transformer 02 55.000000 NULL
Transformer 03 70.000000 NULL
*总是有一列显示为 NULL * .. 有人可以帮我吗?