On 2013/12/22 09:55, Giuseppe Costanzi wrote:
I don't know if I have understood well but the statment
SUM(stats.quantity * (stats.which_month = 1))
SUM(stats.quantity * (stats.which_month = 2))
should be interpreted
SUM stats.quantity IF stats.which_month = 1 is TRUE
SUM stats.quantity IF stats.which_month = 2 is TRUE
Kind of yes, although for more clarity I'd propose it stated like this:
For JAN: Results = SUM ( value ) WHERE (
value = (stats.quantity * _1_) WHEN month is JAN
value = (stats.quantity * _0_) WHEN month is NOT JAN
)
For FEB: Results = SUM ( value ) WHERE (
value = (stats.quantity * _1_) WHEN month is FEB
value = (stats.quantity * _0_) WHEN month is NOT FEB
)
etc.
So that in all cases, "value" contains the value of stats.quantity when the selected month shows up in the iteration loop, and Zero
when any other month shows up, so Summing the values (or indeed doing any other kind of aggregate function on it) will only affect
stats.quantity values for the specific months.
Apologies for the roundabout way of explaining - I never quite had to explain this specific kind of thing to anyone, it's usually a
bit embedded - and I'm sure the same goes for most others on this forum!
Cheers,
Ryan
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users