我有这3个Excel公式可以转换为SQL。
"E1335" =IF(D135=0,0,IF(AND(AU135/D135>=0.8,AU135/D135<1),1,ROUNDDOWN(AU135/D135,0)))
SQL中出现问题了,因为在这一部分中,它链接回(E135)1. if计算并且只是失败。
"F135" =IF(C135=0,0,IF(E135=1,0,ROUNDDOWN((AU135-E135*D135)/C135,0)))
"G135" =IF(B135=0,0,IF(E135=1,0,ROUNDDOWN((AU135-E135*D135-F135*C135)/B135,0)))
CASE WHEN [D135] = 0 THEN 0
WHEN [AU135] / [D135] >= 0.8 AND [AU135] / [D135] < 1 THEN 1
ELSE Floor ([AU135] / [D135])
END AS E135,
CASE WHEN [C135] = 0 OR E135 1 THEN 0
ELSE Floor ([AU135] - [E135] * [D135] / [C135]) END AS [F135]
答案 0 :(得分:0)
我认为这在SQL中是等效的:
第一:
CASE
WHEN [D135] = 0 THEN 0
ELSE CASE
WHEN [AU135] / [D135] >= 0.8 AND [AU135] / [D135] < 1 THEN 1
ELSE FLOOR([AU135] / [D135])
END
END
第二个:
CASE
WHEN [C135] = 0 THEN 0
ELSE CASE
WHEN [E135] = 1 THEN 0
ELSE FLOOR(([AU135] - [E135] * [D135]) / [C135])
END
END
3d:
CASE
WHEN [B135] = 0 THEN 0
ELSE CASE
WHEN [E135] = 1 THEN 0
ELSE FLOOR(([AU135] - [E135] * [D135] - [F135] * [C135]) / [B135])
END
END