On Sat, 21 Dec 2013 17:30:50 +0200 RSmith <rsm...@rsweb.co.za> wrote:
> Just move the scope of the grouping and use Nulls in stead of 0's, > like this: > > SELECT stats.which_year AS year, > SUM(CASE WHEN stats.which_month = 1 THEN stats.quantity ELSE NULL > END) AS gen, ELSE NULL is the default sqlite> create table T ( t int not null primary key ); sqlite> insert into T values (1) ; sqlite> insert into T values (2) ; sqlite> .nullvalue NULL sqlite> select t, case t when 1 then 'one' end as tee from T; 1|one 2|NULL But I would recommend ELSE 0, on the principle that NULL arithmetic is dodgy at best. BTW, "which_month" means the same as "month"; you could tack "which" in front of any name without changing the meaning. --jkl _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users