This query is valid in MySQL. It selects all rows from the prenotazione
table where the user_id
is 18793 and the prenotazione_stato_id
is 10 or 11. The resulting rows are summarized: in the numero
column you get the number of rows found, in the somma
column you get the sum of the valutazione
values. If no rows were selected, SUM()
would return NULL
. To prevent this, IFNULL([expr1],[expr2])
is applied, which returns [expr1]
if it is not null, and [expr2]
if it is null. This makes sure you always return a number.
There is no easy way to do this with Propel, since your result cannot be easily mapped to a Propel object. The best thing you can do is use the underlying database layer (PDO) to escape your parameters and handle the resultset, and you don't open an extra database connection or something like that.