Reputation: 555
I'm stuck with queries. Basically I want to get two results of the same field, according to two where clauses, then. Sum (field1) when (ins_n = 0) and sum (field1) when (ins_n = 1). I hope I explained. Now I can only do so when (ins_n = 0)
"SELECT " +
"SUM(field1) AS incasso1, " +
"FROM Movimentinegozio WHERE ins_n = 0 ";
Upvotes: 1
Views: 60
Reputation: 176154
You can use SUM
and 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);
If you need result in two rows use @Marc B
suggestion:
SELECT ins_n, SUM(field1) AS incasso
FROM Movimentinegozio
WHERE ins_n IN (0, 1)
GROUP BY ins_n
Upvotes: 1