What do I need to change in the SQL to sum the msr_cnt field grouped into project_ref?
select m.project_ref,
( select count(*)
from (values (m.[EWI/IWI]), (m.Glazing), (m.Solar), (m.CWI), (m.Boiler), (m.TRV), (m.LI), (m.RIRI), (m.UFI), (m.ASHP)) as v(col)
where v.col <> ''
) as 'msr_cnt'
from SMSDB1.dbo.ops_measure m
where 'msr_cnt' <> '0'
--group by m.project_ref
The current output is
project_ref | msr_cnt |
---|---|
WHGSHDF | 2 |
WHGSHDF | 2 |
WHGSHDF | 2 |
WHGSHDF | 2 |
WHGSHDF | 2 |
WHGSHDF | 2 |
WHGSHDF | 2 |
I need it to show
project_ref | msr_cnt |
---|---|
WHGSHDF | 14 |
I just can't quite get it over the line.
1条答案
按热度按时间am46iovg1#
Very difficult to answer without a proper set of source data, MRE etc, but I would have thought this should work: