Can db_select cope with mysql "case when" structures?
SelectQuery has the addExpression() method for adding arbitrary expressions. e.g.

$query = db_select('game_sessions', 'm')-&gt;fields('m');
$query-&gt;addExpression('ifnull(max(case when mission = 1 then score end),0)', 'mission_1');


Yields:

SELECT m.*, ifnull(max(case when mission = 1 then score end),0) AS mission_1
FROM {game_sessions} m