Avatar of soozh
soozhFlag for Sweden

asked on 

Group by using a join to produce sets of data

I have a table called #Data and i wish to summerise its contents. See the code below.

 
select 
  msr_Q1Total_Change,
  avg( cast( Has_Act_BasalaBehov as real ) ) as BasalaBehov,
  avg( cast( Has_Act_KognitivtStöd as real ) ) as KognitivtStöd
from #Data 
where msr_Q1Total_Change = 1
group by msr_Q1Total_Change

Open in new window


However i really need to produce the same summarisation for msr_Q1Total_Change  in the range 1 to 12.  So i am looking for 12 seperate results.

Is there a way to write this with a join that returns the values 1-12 ?  Thereby saving me a lot of cut and pasting and 12 seperate expressions.
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
soozh
ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of soozh
soozh
Flag of Sweden image

ASKER

thanks... i must be going crazy not to ahve realised that!
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo