SQL Server “cannot perform an aggregate function on an expression containing an aggregate or a subquery”, but Sybase can
One option is to put the subquery in a LEFT JOIN: Perhaps a better option would be to use SUM with CASE: SQL Fiddle Demo with both