0

What would be the equivalent Excel formula of this SQL query

SELECT SUM(a) FROM table WHERE b < 0;

A     B
----  ----
   1     0
   2    -1 
   3     4
   5    -3

>> 7
gregseth
  • 12,952
  • 15
  • 63
  • 96

4 Answers4

2

Use the SUMIF function.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • That's what I tried, but if I'm not mistaken, the condition is only on one cell or an equality. `SUMIF(B1:B4;<0;A1:A4)` obviously doesn't work, but what to write before the `<`? – gregseth Jun 02 '10 at 22:01
0
=SUMIF(B:B,"<0",A:A)
Paul Kearney - pk
  • 5,435
  • 26
  • 28
0

use SUMIFS(a1:a4,b1:b4,"<0") if values in A1:B4 range

bill
  • 1
0

Given:

Row#    A    B

3       1    0
4       2   -1
5       3    4
6       5   -3

=SUMIF(B3:B6; "<0"; A3:A6)
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480