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.
Author |
Topic |
fatih252
Starting Member
4 Posts |
Posted - 2012-05-09 : 03:45:07
|
HelloI have two queries where i have difficulties combining them. I need this two counts to make an average for my archive table. select count(*) from tbl_app_monitoring as mon where mon.status = 'alive'group by mon.application_id , mon.test_name select count(*) from tbl_app_monitoring as mon , tbl_application as appwhere mon.application_id = app.idgroup by mon.application_id , mon.test_name this is my table: |
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2012-05-09 : 07:12:42
|
what output do u want? |
 |
|
vinu.vijayan
Posting Yak Master
227 Posts |
Posted - 2012-05-09 : 08:17:20
|
Please post the sample data not as an image but as a String of insert statements so that its easy for the people here to use it.What do you mean when you say, "I need this two counts to make an average for my archive table". Please elaborate.Please post the sample data and the Expected Result Set.N 28° 33' 11.93148"E 77° 14' 33.66384" |
 |
|
fatih252
Starting Member
4 Posts |
Posted - 2012-05-09 : 08:58:53
|
quote: Originally posted by vinu.vijayan Please post the sample data not as an image but as a String of insert statements so that its easy for the people here to use it.What do you mean when you say, "I need this two counts to make an average for my archive table". Please elaborate.Please post the sample data and the Expected Result Set.N 28° 33' 11.93148"E 77° 14' 33.66384"
thanks for your answers, i found the solution!:select application_id, test_name,status,count(*) as numberinto #temptbfrom tbl_app_monitoringgroup by application_id, test_name, statusselect application_id , test_name,sum(number) as totalinto #temptb2from #temptbgroup by application_id, test_nameinsert into tbl_app_monitoring_archive (test_name,percentage_status,application_id)select TT1.test_name, cast(((number*1.0) /(total*1.0))*100 as int),TT1.application_id from #temptb TT1 inner join #temptb2 TT2on TT1.application_id = TT2.application_idwhere status = 'alive'group by TT1.test_name, number , total,TT1.application_id [url][/url] |
 |
|
|
|
|
|
|