Monday, May 7, 2012

SQL Query asked by moazzam


select A.bundleid,B.featureid,B.featurecount from (SELECT p1.bundleid,

      cast( ( SELECT featureid + ','

           FROM kepmax_bundlefeature p2

          WHERE p2.bundleid = p1.bundleid

          ORDER BY featureid

            FOR XML PATH('') ) as varchar(8000)) AS featureid, max(cast(FeatureCount as decimal)) as FeatureCount

      FROM kepmax_bundlefeature p1

      GROUP BY bundleid) A
inner join
(select featureid, max(cast(FeatureCount as decimal)) as featurecount from (
    SELECT p1.bundleid,

      cast( ( SELECT featureid + ','

           FROM kepmax_bundlefeature p2

          WHERE p2.bundleid = p1.bundleid

          ORDER BY featureid

            FOR XML PATH('') ) as varchar(8000)) AS featureid, max(cast(FeatureCount as decimal)) as FeatureCount

      FROM kepmax_bundlefeature p1

      GROUP BY bundleid) as T
group by featureid ) B
on A.featureid = B.featureid and A.FeatureCount = B.FeatureCount
order by cast(bundleid as decimal)

No comments:

Post a Comment

Blog Archive