我遇到了疑问。基本上我想得到两个相同字段的结果,根据两个where子句,然后。 当(ins_n = 0)时的Sum(field1)和当(ins_n = 1)时的sum(field1)。我希望我解释一下。现在我只能在(ins_n = 0)
时这样做"SELECT " +
"SUM(field1) AS incasso1, " +
"FROM Movimentinegozio WHERE ins_n = 0 ";
答案 0 :(得分:1)
您可以使用SUM
和CASE
:
SELECT SUM(CASE WHEN ins_n = 0 THEN field1 END) AS incasso0,
SUM(CASE WHEN ins_n = 1 THEN field1 END) AS incasso1
FROM Movimentinegozio
WHERE ins_n IN (0, 1);
如果您需要两行结果,请使用@Marc B
建议:
SELECT ins_n, SUM(field1) AS incasso
FROM Movimentinegozio
WHERE ins_n IN (0, 1)
GROUP BY ins_n