Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 6: Linear Version of the Nested ... > 6.4 Cash Register Tape Problem - Pg. 164

6 . 4 C a s h R e g i s t e r Ta p e P r o b l e m 153 6.3 Finding Levels Getting the level is a little trickier. You count the "parentheses" (i.e., emp_ seq) and then count the number of distinct things inside the parentheses (emp_id); every pair of parentheses moves you up a level. Then you do some algebra and come up with this answer. SELECT :my_guy, 2 * COUNT(DISTINCT P2.emp_id) - COUNT(DISTINCT P2.emp_seq) AS lvl FROM Personnel_Orgchart AS P1, Personnel_Orgchart AS P2 WHERE P1.emp_id = :my_guy AND P2.emp_seq < = (SELECT MIN(emp_seq) FROM Personnel_Orgchart WHERE emp_id = :my_guy); 6.4 Cash Register Tape Problem