Create table Sample ( OriginalDoc VARCHAR(255), ChildDoc VARCHAR(255), Fee MONEY ); INSERT INTO Sample VALUES ( 'AB12456', 'NX12450', NULL ), ( 'CY12345', 'NX23410', NULL ), ( 'CY12345', 'NX23421', NULL ), ( 'CY12345', 'NX23432', NULL ), ( 'NX23410', 'NY23411', NULL ), ( 'NX23410', 'NY23422', NULL ), ( 'NY23422', 'NZ23411', NULL ), ( 'NY23422', 'NZ23422',NULL); with cte as(select *, OriginalDoc as Parent from Sample s1 where not exists(select * from Sample s2 where s2.ChildDoc = s1.OriginalDoc) union all select s.*, c.Parent from cte c join Sample s on c.ChildDoc = s.OriginalDoc ) select Parent, count(*)*0.4 as Fee from cte group by Parent
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE