Monday, November 14, 2022

SQL Question

SELECT Sum(Table2.dead) AS ['Sum Of dead non-firearm dead > 3'], Avg(Table2.dead) AS ['Avg Of non-firearm dead dead > 3']

FROM Table2

WHERE dead > 3 and (firearm_unknown = 0 and pistol = 0 and rifle = 0 and shotgun = 0 and machine_gun = 0);

The two outputs are both blank.  This on the other hand:

SELECT Sum(Table2.dead) AS [Sum Of dead], Avg(Table2.dead) AS ['Avg Of dead']

FROM Table2

WHERE dead > 3 and (firearm_unknown = 1 or pistol = 1 or rifle = 1 or shotgun = 1 or machine_gun = 1);

produces what I need.

It turns that my weapon type columns should have been defined as BOOLEAN.  These are really booleans; did anyone die of this weapon type.  Most early news accounts are careless in reporting who died from which weapon.  Also, when you bash someone's head with an axe then shoot them,    determining cause was hard back then and might be hard today.

Testing for IS NULL did the trick.  

No comments:

Post a Comment