Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
if i got 2 tableTable1-------WorkWeek Value28 21228 24228 43528 53429 25429 54230 984Table2------WorkWeek ValueX28 45328 2229 12429 23229 1230 5430 54630 324i want my result asWorkWeek Sum(Table1.Value) AS SumValCOUNT(Table2.ValueX) AS CountValX Sum(Table1.Value) / COUNT(Table2.ValueX) AS AnswerWorkWeek SumVal CountValX Answer---------------------------------------------28 1423 2 711529 706 3 265.3330 984 3 328so how can my sql statement should look like... join 2 table which get the sum of Value in Table1 and count the row of table 2 which both group by WorkWeek and take both to devided it...Is it possible make it in one sql statement?
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2005-09-22 : 02:59:47
Try this
Select T1.WorkWeek, SumVal,CountValX,SumVal/CountValX*1.0 from ( Select WorkWeek, sum(value) as SumVal from table1 group by WorkWeek ) T1 inner join ( Select WorkWeek, count(ValueX) as CountValX from table2 group by WorkWeek ) T2on T1.WorkWeek=T2.WorkWeek