Marina
Marina

Reputation: 3322

What does the use of an asterisk (*) mean in a mysql select statement, other than a wildcard?

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

Answers (3)

Alexander Pavlov
Alexander Pavlov

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

jon
jon

Reputation: 6246

It's a standard multiplication operator,

select 2 * 2 

= 4

:)

Upvotes: 0

Mike Pone
Mike Pone

Reputation: 19330

It is a multiplication operation.

example 2*3=6

Upvotes: 0

Related Questions