我正在尝试使用内部连接连接 4 个表,其中一个别名为“m”的表返回定义条件的空结果集(这是一种有效的可能性)。我想在我的 IF 语句中为空结果集做一个规定:
IF(((((SUM(m.TTL_ONLINE_COUNT)+SUM(m.TTL_OFFLINE_COUNT))*100))> TAV.`ThresholdValue`) OR ISNULL(m.TTL_ONLINE_COUNT)
目前,我正在尝试检查该返回数据集的一列是否为空,但它没有按预期工作。我怎样才能做出这样的规定?
SELECT AQ.Adate, TE.EmployeeID, TE.`WorkerLevelID`,TAV.ManufacturingProductID,TAV.SubOfficeID,Te.SubstationCode,TAV.`AllowID`,TAV.`WorkerLevelID`,TAV.ThresholdValue,TAV.RewardValue,
CASE AQ.Status
WHEN '0' OR '6' THEN
IF(((((SUM(m.TTL_ONLINE_COUNT)+SUM(m.TTL_OFFLINE_COUNT))*100))> TAV.`ThresholdValue`) OR ISNULL(m.TTL_ONLINE_COUNT),
CASE TAV.RateType
WHEN 'Monthly' THEN
TAV.RewardValue/DAY(LAST_DAY(P_DateFrom))
WHEN 'Yearly' THEN
TAV.RewardValue/365.25
END, 0)
END AS FPYAllowance
FROM TempEmployee TE
INNER JOIN TempAllowValid TAV ON TE.ManufacturingProductID = TAV.ManufacturingProductID AND TE.SubOfficeID =TAV.SubOfficeID AND TE.WorkerLevelID = TAV.WorkerLevelID
INNER JOIN Attendance_QlikView AQ ON P_DateFrom = AQ.ADate
INNER JOIN `mwooriginbasedfault` m ON m.Defect_Origin_Code = TE.SubstationCode AND m.Defect_Date = AQ.ADate
WHERE (TAV.AllowID = 3 OR Tav.AllowID=10 )
GROUP BY AQ.Adate, TE.EmployeeID);