\n SELECT\n o.ordernum,\n o.orderdate,\n CASE SUM(\n CASE e.status\n WHEN 'open' THEN 1\n ELSE 0\n END\n )\n WHEN 0 THEN 0\n ELSE 1 END as has_escalation\n FROM tbl_order AS o\n LEFT JOIN tbl_escalation AS e\n ON o.ordernum = e.ordernum\n GROUP BY o.ordernum, o.orderdate\n ORDER BY\n CASE SUM(\n CASE e.status\n WHEN 'open' THEN 1\n ELSE 0\n END\n )\n WHEN 0 THEN 0\n ELSE 1 END DESC, o.ordernum\n
If this doesn't work, then something like it has a good chance.
Cheers,
Ben