SELECT
DT, FlowParam, Abs_P, T, Volume, Energy, FlowTime_T,
(SELECT ' > 1 ' AS Expr1 WHERE (
(SELECT COUNT(*) AS Expr2
FROM dbo.BACS_Alarm_1
WHERE
(DT_T >= dbo.BACS_HourFlow_1.DT_T) AND
(DT_T <= dbo.BACS_HourFlow_1.DT_T + dbo.BACS_HourFlow_1.FlowTime_T)
) > 1
)) AS Something
FROM dbo.BACS_HourFlow_1
我需要輸出領域AS Something
從BACS_Alarm_1
表,如果WHERE... = 1
和輸出Null
如果= 0 ...和輸出我的消息,如果> 1(這已經制造)SQL [案件查詢視圖]
哪有我意識到這種情況?
所以 如果
(SELECT COUNT(*) AS Expr2
FROM dbo.BACS_Alarm_1
WHERE
(DT_T >= dbo.BACS_HourFlow_1.DT_T) AND
(DT_T <= dbo.BACS_HourFlow_1.DT_T + dbo.BACS_HourFlow_1.FlowTime_T)
) > 1
I輸出 '> 1' 的東西
如果= 1個I輸出從dbo.BACS_Alarm_1 場如果= 0 I輸出0或空的
所以基本上,如果子查詢(輸出到'Something'列)的結果爲0,你希望它是'Null',如果是1,則輸出別的,如果它大於1,這是一個自定義消息? – Anthony 2010-01-26 08:24:20
這是MySQL還是別的? – Anthony 2010-01-26 08:24:44
什麼數據庫?您應該嘗試使用連接而不是相關的子查詢。 – 2010-01-26 08:24:59