sql server - Group a Group in SQL -


i have following query:

select inspections.pipe_segment_reference, (count(*) * conditions.structural_grade) structural_rating (     select inspections.pipe_segment_reference, conditions.structural_grade     conditions     inner join inspections     on conditions.inspectionid = inspections.inspectionid     conditions.structural_grade not null ) group inspections.pipe_segment_reference, conditions.structural_grade; 

which outputs

22, 2 22, 4 79, 2 79, 5 79, 3 

i want further group pipe_segment_reference output of

22, 6 79, 10 

i tried adding additional select around query above can't work.

you're on right track adding additional select around working query. try this...

select     derivedyourinitialquery.pipe_segment_reference,     sum(derivedyourinitialquery.structural_rating) newtotal     (     select inspections.pipe_segment_reference,     (count(*) * conditions.structural_grade) structural_rating     (         select inspections.pipe_segment_reference, conditions.structural_grade         conditions         inner join inspections         on conditions.inspectionid = inspections.inspectionid         conditions.structural_grade not null     )     group inspections.pipe_segment_reference, conditions.structural_grade     ) derivedyourinitialquery group     derivedyourinitialquery.pipe_segment_reference 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -