select date, count(fail) as fail,count(win) as win from
(select date,(case (result) when 'fail' then 'fail' end ) as fail,(case (result) when 'win' then 'win' end ) as win from games
) d group by date
select Name, Year , Month ,Count(Amount) as Income from
(select b.Name ,a.[Year] as Year ,a.[Month] as Month ,a.Amount as Amount from Test_Amount a left join Test_Users b on a.UserId=b.Id )
c group by Name,Year,Month