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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need sql query

Author  Topic 

venkatakondareddy
Starting Member

17 Posts

Posted - 2008-12-20 : 06:01:59
Hi
here i have problem while writing query. i.e., here i have 2 tables by the name of Asset and Issue. In Asset table i have ParentAssetId and AssetId, and in Issue table AssetId and InternalIssueRisk.

Now the Question is: per AssetId aggregate all children and aggregate issuerisk.

select Kaon.Asset.ParentAssetId , Avg(InternalIssueRiskId)
from Kaon.Asset,Kaon.Issue where
Kaon.Asset.AssetId=(select sum(Kaon.Issue.AssetId) from Kaon.Issue) group by ParentAssetId

In feature Issue table may contain no of fields.
So Any one knows send the answer to my mail...
venkatakondareddy@hotmail.com
Please...

Regards
---------
Venkat

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-20 : 09:16:23

Select as.parentissueid, sum(is.assetid) as childasset,avg(is.internalIssuerisk) as risk
From asset as inner join Issue is
On as.assetid= is.assetid group by as. Parentissueid
Go to Top of Page

venkatakondareddy
Starting Member

17 Posts

Posted - 2008-12-22 : 05:14:40
thanks a lot sodeep for giving reply for my query..
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-22 : 05:49:12
You will need to have a recursive CTE if there are more than one level of parent-child relationship.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

venkatakondareddy
Starting Member

17 Posts

Posted - 2008-12-23 : 02:31:06
Okie peso,
can you give explain how to map more than one table using CTE Hierarchy recursive?

Regards
----------
Venkat
Go to Top of Page
   

- Advertisement -