SQL UPDATE,带有除法和INNER JOIN的SELECT CASE

时间:2018-12-14 12:56:32

标签: sql sql-server

我尝试了很多方法,但没有任何一项可行,只有在t2中t1.total和t1.quantity在t2中处于un range范围内时,才需要更新t1

我的代码:

UPDATE t1
SET t1.Code_142 = 'OK' 
SELECT CASE WHEN quantity = 0 THEN NULL ELSE TOTAL/quantity END AS q
FROM Servicios_de_control_de_calidad_de_agua_potable as t1
INNER JOIN Con_A as t2 ON t1.ID = t2.ID
WHERE t1.q BETWEEN t2.Mins AND t2.Maxs

致谢

3 个答案:

答案 0 :(得分:3)

您可以按照以下说明尝试,希望对您有帮助

UPDATE t1
SET t1.Code_142 = 'OK' 
FROM Servicios_de_control_de_calidad_de_agua_potable as t1
INNER JOIN Con_A as t2 ON t1.ID = t2.ID
WHERE (CASE WHEN quantity = 0 THEN NULL ELSE TOTAL/quantity END) BETWEEN t2.Mins AND t2.Maxs

答案 1 :(得分:1)

您要查找的查询应如下所示

UPDATE t1
SET t1.Code_142 = 'OK' 
FROM Servicios_de_control_de_calidad_de_agua_potable  t1
INNER JOIN Con_A  t2 ON t1.ID = t2.ID
WHERE CASE WHEN quantity = 0 THEN t2.Mins-1 ELSE TOTAL/quantity END BETWEEN t2.Mins AND t2.Maxs

答案 2 :(得分:1)

很显然,我无法测试此代码,但是您可能需要以下代码:

class Module3 {
    static testFunction() {
            const { Module1 } = require("./Module1");
            Module1.testFunction();
    }
}
module.exports = { Module3 };