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,809
  • 5
  • 26
  • 45
Massimo Griffani
  • 767
  • 8
  • 18

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,357
  • 3
  • 19
  • 31
1
SELECT sum(sbc750) FROM cabine where evaso is null or evaso<>1;
farbiondriven
  • 2,450
  • 2
  • 15
  • 31