select a.MouthsId as 月份,
SUM(case when [years]='2017' and g.Code='19191919' and g.GprsType=1 then b.WaterConsumption else 0 end),
SUM(case when [years]='2017' and g.Code='19191919' and g.GprsType=2 then b.WaterConsumption else 0 end)
from Mouth as a left JOIN [MeterRecordHistory]
as b on a.MouthsId=b.mouths
left JoIn Meter as m on m.id=b.MeterId
left JoIn Hub as h on h.Id=m.HubId
left JoIn Gprs as g on g.Id=h.GprsId
group by a.MouthsId order by a.MouthsId
https://www.cnblogs.com/xinjian/archive/2010/11/17/1879959.html
case when [years]='2017' and g.Code='19191919' and g.GprsType=1 then b.WaterConsumption else 0 end
用三目运算就可以了。