Reputation: 3322
I came across a mysql query that looks like this:
SELECT
SUM(some_amount*(some_field!=90)*(some_date < '2011-04-22'))
, SUM(some_amount*(some_field =90)*(some_date < '2011-04-22')*(another_field IS NULL))
FROM
some_table
What does the * mean in the select statement in this case?
Upvotes: 0
Views: 338
Reputation: 32286
Looks like CAST()
is not necessary for boolean-to-integer conversions. Multiplication is used to convert the sum to 0 for unwanted rows (using the fact that boolean true
can be cast to 1
and false
to 0
):
some_amount*(some_field!=90)*(some_date < '2011-04-22')
if some_field == 90
or some_date >= '2011-04-22'
, the corresponding term will evaluate to 0, thereby converting the entire expression to 0.
Upvotes: 1