View Single Post
  #2 (permalink)  
Old 06-27-09, 22:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,083
Code:
SELECT temp_id
     , a_id
     , SUM(emp_cnt) AS emp_cnt
  FROM (
       /* insert your query here */ 
       select a.temp_id, 
              a.id as a_id, 
              b.id as b_id,
              (select count(*) cnt from EMP where id = b.id) as EMP_CNT
       from DEPT a, DEPT b
       where  a.domain = 'X'
       and b.domain <> 'X'
       and a.temp_id = b.temp_id
       AND b.temp_id in (select temp_id from DEPT group by temp_id having count(*) > 2)
       ) AS derivedtable
GROUP
    BY temp_id
     , a_id
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote