2015-12-09 98 views
1

我被查詢困住了。基本上,我想根據兩個條款,然後得到兩個相同領域的結果。 sum(field1)when(ins_n = 0)和sum(field1)when(ins_n = 1)。我希望我解釋一下。現在,我只能這樣做時(ins_n = 0)SQLite Select where where clause

"SELECT " + 
"SUM(field1) AS incasso1, " +     
"FROM Movimentinegozio WHERE ins_n = 0 "; 
+0

'選擇...其中ins_n在由ins_n'(0,1)組? –

回答

1

您可以使用SUMCASE:如果您需要產生兩行使用

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); 

SqlFiddleDemo

@Marc B建議:

SELECT ins_n, SUM(field1) AS incasso 
FROM Movimentinegozio 
WHERE ins_n IN (0, 1) 
GROUP BY ins_n 

SqlFiddleDemo2

+1

您的解決方案完美無缺,謝謝 – user2847219