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 Am'I still in the darkness? On Sun, Dec 22, 2013 at 4:35 AM, RSmith <rsm...@rsweb.co.za> wrote: > Boolean Logic 101 - Feel free to skip if this is not your thread! > ------------------------------------------------------------ > ------------------------- > > In addition to other replies - Boolean logic is interesting in that it has > no real arithmetic value and can have only true or false as a value. It > doesn't fit too well as a high-level storage value of a system even though > it permeates low-level storage in every way - it can't be null for > instance, but in an RDBMS it _can_ be Null and it _can_ be arithmetic by > taking on the values 0 and 1 for false and true respectively. This has the > added advantage that it can be used in arithmetic statements which is what > Igor used to save considerable amounts of typing in your query. > > Whether or not it is faster in execution than a case statement is probably > up to some testing, but I am willing to bet it is somewhat faster > considering the relative complexity of a CASE statement. > > Any statement containing a comparison operator ends up being a Boolean > statement because it can be found to either be so, or not be so. Month is > not Boolean, but (Month = January) is definitely Boolean, because the > comparison is either true or false depending on the value of "Month". > > Similarly any attribute can be Boolean if it is found to be an attribute > of an object. Giuseppe is not Boolean, but he is human and likely male, so > that: > (Giuseppe = Human) is true or 1, and > (Giuseppe = Female) is false or 0. > > For RDBMS and indeed most programming languages, any Boolean evaluated > result can directly be inferred as the arithmetic values 0 and 1 so that I > could make some programmatic assumptive statements based on it, such as: > > HumanX's fertility period recurs every (28 * (HumanX = Female)) days. This > will be 0 days for men (28 * false) = (28 * 0) = 0, and 28 for ladies as > (28 * true) = (28 * 1) = 28 in the same logic. > > Similarly your odds of balding is roughly 0.04 + (35/Age)*((HumanX = Male) > * 10) since men have a roughly 40% chance of balding by age 35 which is > about 10 times more likely than women and the odds increase with age[1]. > > > Hope this makes clear how Booleans are used mathematically in high-level > code. Have a great day! > Ryan > > > [1] - http://www.statisticbrain.com/hair-loss-statistics/ > > > > On 2013/12/21 22:24, Giuseppe Costanzi wrote: > >> ...but stats.which_month is not a boolean, it represent a month... >> >> >> > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users