I have query :
SELECT user_name, group_id,
CASE WHEN col_1 = 1 THEN 0
WHEN col_2 = 1 THEN 1
WHEN col_3 = 1 THEN 2
END as merge_col
FROM some_table
WHERE group_id = 10
ORDER BY merge_col.
How using ZF2 and Zend\..\Sql, I can implement this query ?
Update:
Thank who try to help me. It is work as following:
$select->columns(array(
'user_name',
'group_id',
'merge_col' => new Expression('CASE WHEN col_1 = 1 THEN 0
WHEN col_2 = 1 THEN 1
WHEN col_3 = 1 THEN 2 END')))
->where (array('group_id'=> 10))
->order ('merge_col');
is there a better answer ?
Thanks.