1

I have a table "Cabine" with fields "SBC750" (integer) and "Evaso" (tinyint)

The field Evaso can be 1, 0 or Null

I'm looking for the sum of all sbc750 where Evaso is NOT 1.

I tried with

select sum(sbc750) from cabine  where evaso<>1;

but the result is NULL: why???

If I use

select sum(sbc750) from cabine 

I obtain 55 and if I use

select sum(sbc750) from cabine where evaso=1

I obtain 34!

So the results might be 21 and not Null. Please help me

S3S
  • 24,483
  • 5
  • 24
  • 44
Massimo Griffani
  • 717
  • 6
  • 17

2 Answers2

1

With the NULL-safe equality operator you should get the desired results:

select sum(sbc750) from cabine where not evaso<=>1;

Also see here for reference.

MatSnow
  • 7,132
  • 3
  • 20
  • 31
1
SELECT sum(sbc750) FROM cabine where evaso is null or evaso<>1;
farbiondriven
  • 2,273
  • 2
  • 17
  • 29