Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.27 KB | None | 0 0
  1. Question 1
  2. Needs Grading
  3.  
  4. Display full name of the employees using format of Last, First, their hire date and salary together with their department name and city, but only for departments which names start with an A or the department name starts with S and end with g.
  5.  
  6. Sort by department name and employee name. Show me one row and tell me how many rows were in the output
  7.  
  8. Sample output: Termede, Ingrid 01-DEC-14 11000 Sales city
  9.  
  10. Selected Answer:
  11.  
  12. SELECT E.LAST_NAME||' '||E.FIRST_NAME AS "FULLL NAME" ,E.HIRE_DATE, E.SALARY, D.DEPARTMENT_NAME,L.CITY
  13.  
  14.  
  15. FRoM EMPLOYEES E, DEPARTMENTS D, LOCATIONS L
  16.  
  17.  
  18. WHERE E.DEPARTMENT_ID=D.DEPARTMENT_ID
  19.  
  20.  
  21. AND L.LOCATION_ID=D.LOCATION_ID
  22.  
  23.  
  24. AND (D.DEPARTMENT_NAME LIKE 'A%' OR D.DEPARTMENT_NAME LIKE 'S%g')
  25.  
  26.  
  27. ORDER BY 4,1;
  28.  
  29.  
  30.  
  31.  
  32.  
  33. =====
  34.  
  35.  
  36. output
  37.  
  38.  
  39. =====
  40.  
  41.  
  42. Gietz William 94-06-07 8300 Accounting Seattle
  43.  
  44.  
  45. 9 total rows
  46.  
  47.  
  48. Correct Answer:
  49. Correct
  50. SELECT E.LAST_NAME||' '||E.FIRST_NAME AS "FULLL NAME" ,E.HIRE_DATE, E.SALARY, D.DEPARTMENT_NAME,L.CITY
  51.  
  52. FROM EMPLOYEES E, DEPARTMENTS D, LOCATIONS L
  53.  
  54. WHERE E.DEPARTMENT_ID=D.DEPARTMENT_ID -- these 2 lines cover the joins
  55.  
  56. AND L.LOCATION_ID=D.LOCATION_ID -- you may use another join style
  57.  
  58. AND (D.DEPARTMENT_NAME LIKE 'A%' OR D.DEPARTMENT_NAME LIKE 'S%g')
  59.  
  60. ORDER BY D.DEPARTMENT_NAME,"FULL NAME";
  61.  
  62. name HIRE_DATE SALARY DEPARTMENT_NAME CITY
  63.  
  64. ----------------------------------------------- --------- ---------- ------------------------------ ------------------------------
  65.  
  66. Gietz, William 07-JUN-94 8300 Accounting Seattle
  67.  
  68. Higgins, Shelley 07-JUN-94 12000 Accounting Seattle
  69.  
  70. Whalen, Jennifer 17-SEP-87 4400 Administration Seattle
  71.  
  72.  
  73.  
  74. should get 9 rows
  75.  
  76. Response Feedback: [None Given]
  77. Question 2
  78. Needs Grading
  79.  
  80. Display the department name, city, street address and postal code for all departments sorted by city and department name.
  81.  
  82. Selected Answer:
  83.  
  84. select department_id, city, street_address, postal_code
  85.  
  86.  
  87. from departments d, locations l
  88.  
  89.  
  90. where d.location_id = l.location_id
  91.  
  92.  
  93. order by city, department_id;
  94.  
  95.  
  96.  
  97.  
  98.  
  99. =====
  100.  
  101.  
  102. output
  103.  
  104.  
  105. =====
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. DEPARTMENT_ID CITY STREET_ADDRESS POSTAL_CODE
  118.  
  119.  
  120. ------------- ------------------------------ ---------------------------------------- ------------
  121.  
  122.  
  123. 80 Oxford Magdalen Centre, The Oxford Science Park OX9 9ZB
  124.  
  125.  
  126. 10 Seattle 2004 Charade Rd 98199
  127.  
  128.  
  129. 90 Seattle 2004 Charade Rd 98199
  130.  
  131.  
  132. 110 Seattle 2004 Charade Rd 98199
  133.  
  134.  
  135. 190 Seattle 2004 Charade Rd 98199
  136.  
  137.  
  138. 200 Seattle 2004 Charade Rd 98199
  139.  
  140.  
  141. 60 Southlake 2014 Jabberwocky Rd 26192
  142.  
  143.  
  144. 20 Toronto 147 Spadina Ave M5V 2L7
  145.  
  146.  
  147. 50 south San Francisco 2011 Interiors Blvd 99236
  148.  
  149.  
  150.  
  151.  
  152.  
  153. 9 rows selected.
  154.  
  155.  
  156. Correct Answer:
  157. Correct
  158. SELECT department_name, city, street_address, postal_code
  159.  
  160. FROM departments JOIN locations USING (location_id)
  161.  
  162. ORDER BY city, department_name;
  163.  
  164. DEPARTMENT_NAME CITY STREET_ADDRESS POSTAL_CODE
  165.  
  166. ------------------------------ ------------------------------ ---------------------------------------- ------------
  167.  
  168. Sales Oxford Magdalen Centre, The Oxford Science Park OX9 9ZB
  169.  
  170. Accounting Seattle 2004 Charade Rd 98199
  171.  
  172. Administration Seattle 2004 Charade Rd 98199
  173.  
  174. Contracting Seattle 2004 Charade Rd 98199
  175.  
  176. Executive Seattle 2004 Charade Rd 98199
  177.  
  178. Shipping South San Francisco 2011 Interiors Blvd 99236
  179.  
  180. IT Southlake 2014 Jabberwocky Rd 26192
  181.  
  182. Marketing Toronto 147 Spadina Ave M5V 2L7
  183.  
  184.  
  185.  
  186. 8 rows selected
  187.  
  188. Response Feedback: [None Given]
  189. Question 3
  190. Needs Grading
  191.  
  192. Display the full name of the manager of each department in states/provinces of Ontario, California, Bavaria and Washington along with the department name, city, postal code and province name. Sort the output by city and then by department name.
  193.  
  194. Selected Answer:
  195. select first_name, last_name, job_id, city, postal_code, state_province
  196.  
  197.  
  198.  
  199. from employees E
  200.  
  201.  
  202.  
  203. join departments D
  204.  
  205. ON E.employee_id = D.manager_id
  206.  
  207. join locations L
  208.  
  209. on D.location_id = L.location_id
  210.  
  211.  
  212.  
  213. where state_province = 'Ontario' or state_province = 'California'
  214.  
  215.  
  216.  
  217. or state_province = 'Bavaria' or state_province = 'Washington'
  218.  
  219.  
  220.  
  221. order by 4,2;
  222.  
  223.  
  224.  
  225.  
  226.  
  227. =====
  228.  
  229. output
  230.  
  231. =====
  232.  
  233.  
  234.  
  235.  
  236.  
  237. FIRST_NAME LAST_NAME JOB_ID CITY POSTAL_CODE STATE_PROVINCE
  238.  
  239. -------------------- ------------------------- ---------- ------------------------------ ------------ -------------------------
  240.  
  241. Shelley Higgins AC_MGR Seattle 98199 Washington
  242.  
  243. Steven King AD_PRES Seattle 98199 Washington
  244.  
  245. Jennifer Whalen AD_ASST Seattle 98199 Washington
  246.  
  247. Eleni Zlotkey SA_MAN Seattle 98199 Washington
  248.  
  249. Michael Hartstein MK_MAN Toronto M5V 2L7 Ontario
  250.  
  251. Kevin Mourgos ST_MAN south San Francisco 99236 California
  252.  
  253.  
  254.  
  255. 6 rows selected.
  256.  
  257.  
  258. Correct Answer:
  259. Correct
  260.  
  261. SELECT distinct m.last_name as "Manager",
  262.  
  263. department_name, city, postal_code, state_province
  264.  
  265. FROM employees E
  266.  
  267. JOIN employees M
  268.  
  269. On (e.manager_id = m.employee_id)
  270.  
  271. JOIN departments D
  272.  
  273. on (m.manager_id = d.manager_id)
  274.  
  275. JOIN locations L
  276.  
  277. USING (location_id)
  278.  
  279. WHERE LOWER(state_province) IN ('ontario', 'bavaria', 'california', 'washington')
  280.  
  281. ORDER BY city, department_name;
  282.  
  283. Manager DEPARTMENT_NAME CITY POSTAL_CODE STATE_PROVINCE
  284.  
  285. ------------------------- ------------------------------ ------------------------------ ------------ -------------------------
  286.  
  287. De Haan Executive Seattle 98199 Washington
  288.  
  289. Hartstein Executive Seattle 98199 Washington
  290.  
  291. Kochhar Executive Seattle 98199 Washington
  292.  
  293. Mourgos Executive Seattle 98199 Washington
  294.  
  295. Zlotkey Executive Seattle 98199 Washington
  296.  
  297.  
  298. Response Feedback: [None Given]
  299. Question 4
  300. Needs Grading
  301.  
  302. Display employee’s Managers ID, managers Last Name and employee number nd last name
  303.  
  304. Label the columns Manager, Mgr# ,Employee and Emp#, respectively. Sort by manager number
  305.  
  306. Selected Answer:
  307. SELECT M.employee_id as MGR#,
  308.  
  309. M.last_name AS Manager,
  310.  
  311. W.last_name AS Employee,
  312.  
  313. w.employee_id as Emp#
  314.  
  315.  
  316.  
  317. FROM employees W JOIN employees M
  318.  
  319. ON W.manager_id = M.employee_id
  320.  
  321.  
  322.  
  323. order by 1;
  324.  
  325.  
  326.  
  327. =====
  328.  
  329. output
  330.  
  331. ======
  332.  
  333.  
  334.  
  335. MGR# MANAGER EMPLOYEE EMP#
  336.  
  337. ---------- ------------------------- ------------------------- ----------
  338.  
  339. 100 King Kochhar 101
  340.  
  341. 100 King De Haan 102
  342.  
  343. 100 King Mourgos 124
  344.  
  345. 100 King Zlotkey 149
  346.  
  347. 100 King Hartstein 201
  348.  
  349. 101 Kochhar Whalen 200
  350.  
  351. 101 Kochhar Higgins 205
  352.  
  353. 102 De Haan Hunold 103
  354.  
  355. 103 Hunold Ernst 104
  356.  
  357. 103 Hunold Lorentz 107
  358.  
  359. 124 Mourgos Rajs 141
  360.  
  361. 124 Mourgos Davies 142
  362.  
  363. 124 Mourgos Matos 143
  364.  
  365. 124 Mourgos Vargas 144
  366.  
  367. 149 Zlotkey Abel 174
  368.  
  369. 149 Zlotkey Vargas 176
  370.  
  371. 149 Zlotkey Grants 178
  372.  
  373. 149 Zlotkey de Man 180
  374.  
  375. 149 Zlotkey Flertjan 1
  376.  
  377. 149 Zlotkey Grovlin 3
  378.  
  379. 149 Zlotkey Smertal 4
  380.  
  381. 149 Zlotkey Mustaine 5
  382.  
  383. 149 Zlotkey Harvey 6
  384.  
  385. 149 Zlotkey LeDuc 7
  386.  
  387. 149 Zlotkey Bergsteige 8
  388.  
  389. 149 Zlotkey Gruber 9
  390.  
  391. 149 Zlotkey Sanchez 11
  392.  
  393. 149 Zlotkey Chancevente 12
  394.  
  395. 149 Zlotkey Torson 14
  396.  
  397. 149 Zlotkey Cornel 15
  398.  
  399. 149 Zlotkey Gibbons 16
  400.  
  401. 149 Zlotkey Pallomine 17
  402.  
  403. 149 Zlotkey Jacobs 18
  404.  
  405. 149 Zlotkey Strandherst 19
  406.  
  407. 149 Zlotkey Brigade 21
  408.  
  409. 149 Zlotkey Litrand 22
  410.  
  411. 149 Zlotkey Armarillo 23
  412.  
  413. 149 Zlotkey Mot 24
  414.  
  415. 149 Zlotkey Turcotte 25
  416.  
  417. 149 Zlotkey LeBlanc 26
  418.  
  419. 149 Zlotkey Rodriguez 27
  420.  
  421. 149 Zlotkey Young 28
  422.  
  423. 149 Zlotkey Loo Nam 29
  424.  
  425. 149 Zlotkey Chan 30
  426.  
  427. 149 Zlotkey Wandiko 33
  428.  
  429. 149 Zlotkey Gregson 34
  430.  
  431. 149 Zlotkey Krain 35
  432.  
  433. 149 Zlotkey Termede 36
  434.  
  435. 149 Zlotkey Testorok 39
  436.  
  437. 149 Zlotkey Whiteduck 40
  438.  
  439. 149 Zlotkey Montoya 41
  440.  
  441. 201 Hartstein Fay 202
  442.  
  443. 205 Higgins Gietz 206
  444.  
  445.  
  446.  
  447. 53 rows selected.
  448.  
  449.  
  450. Correct Answer:
  451. Correct
  452. Will look like this , just different order of columns and more results (over 50 rows)
  453.  
  454. SELECT e.last_name as "Employee", e.employee_id "Emp#", m.last_name as "Manager", e.manager_id as "Mgr#"
  455.  
  456. FROM employees e LEFT OUTER JOIN employees m ON (e.manager_id = m.employee_id);
  457.  
  458. Employee Emp# Manager Mgr#
  459. ------------------------- ---------- ------------------------- ----------
  460. Zlotkey 149 King 100
  461. Kochhar 101 King 100
  462. De Haan 102 King 100
  463. Mourgos 124 King 100
  464. Hartstein 201 King 100
  465. Whalen 200 Kochhar 101
  466. Higgins 205 Kochhar 101
  467. Hunold 103 De Haan 102
  468. Ernst 104 Hunold 103
  469. Lorentz 107 Hunold 103
  470. Rajs 141 Mourgos 124
  471. Davies 142 Mourgos 124
  472. Vargas 144 Mourgos 124
  473. Matos 143 Mourgos 124
  474. Abel 174 Zlotkey 149
  475. Taylor 176 Zlotkey 149
  476. Grant 178 Zlotkey 149
  477. Fay 202 Hartstein 201
  478. Gietz 206 Higgins 205
  479. King 100
  480.  
  481. 20 rows selected
  482.  
  483. NOTE: left join required to include employees without value for manager_id since manager_id in employees table permits nulls. But this is lab 5a that is about simpler joins.
  484.  
  485.  
  486.  
  487.  
  488. Response Feedback: [None Given]
  489. Question 5
  490. Needs Grading
  491.  
  492. Display the location id, address, city, state and country for each location id.
  493.  
  494. Selected Answer:
  495. SELECT D.location_id,
  496.  
  497. L.street_address,
  498.  
  499. L.city,
  500.  
  501. L.state_province,
  502.  
  503. L.country_id
  504.  
  505.  
  506.  
  507. FROM Departments D JOIN Locations L
  508.  
  509. ON D.Location_id = L.location_id
  510.  
  511.  
  512.  
  513. order by 1;
  514.  
  515.  
  516.  
  517. ======
  518.  
  519. output
  520.  
  521. ======
  522.  
  523.  
  524.  
  525. LOCATION_ID STREET_ADDRESS CITY STATE_PROVINCE CO
  526.  
  527. ----------- ---------------------------------------- ------------------------------ ------------------------- --
  528.  
  529. 1400 2014 Jabberwocky Rd Southlake Texas US
  530.  
  531. 1500 2011 Interiors Blvd south San Francisco California US
  532.  
  533. 1700 2004 Charade Rd Seattle Washington US
  534.  
  535. 1700 2004 Charade Rd Seattle Washington US
  536.  
  537. 1700 2004 Charade Rd Seattle Washington US
  538.  
  539. 1700 2004 Charade Rd Seattle Washington US
  540.  
  541. 1700 2004 Charade Rd Seattle Washington US
  542.  
  543. 1800 147 Spadina Ave Toronto Ontario CA
  544.  
  545. 2500 Magdalen Centre, The Oxford Science Park Oxford
  546.  
  547.  
  548. Correct Answer:
  549. Correct
  550. SELECT location_id, street_address, city, state_province, country_name
  551.  
  552. FROM locations LEFT JOIN countries using (country_id);
  553.  
  554. NOTE: left join required to include locations without value for country_id since country_id in locations table permits nulls
  555.  
  556.  
  557.  
  558. ALTERNATE solution:
  559.  
  560. SELECT location_id, street_address, city, state_province, country_name
  561.  
  562. FROM countries RIGHT JOIN locations using (country_id);
  563.  
  564. L OCATION_ID STREET_ADDRESS CITY STATE_PROVINCE COUNTRY_NAME
  565. ----------- ---------------------------------------- ------------------------------ ------------------------- ----------------------------------------
  566. 1000 1297 Via Cola di Rie Roma Italy
  567. 1100 93091 Calle della Testa Venice Italy
  568. 1200 2017 Shinjuku-ku Tokyo Tokyo Prefecture Japan
  569. 1300 9450 Kamiya-cho Hiroshima Japan
  570. 1400 2014 Jabberwocky Rd Southlake Texas United States of America
  571. 1500 2011 Interiors Blvd south San Francisco California United States of America
  572. 1600 2007 Zagora St South Brunswick New Jersey United States of America
  573. 1700 2004 Charade Rd Seattle Washington United States of America
  574. 1800 147 Spadina Ave Toronto Ontario Canada
  575. 1900 6092 Boxwood St Whitehorse Yukon Canada
  576. 2000 40-5-12 Laogianggen Beijing China
  577. 2100 1298 Vileparle (E) Bombay Maharashtra India
  578. 2200 12-98 Victoria Street Sydney New South Wales Australia
  579. 2300 198 Clementi North Singapore Singapore
  580. 2400 8204 Arthur St London United Kingdom
  581. 2500 Magdalen Centre, The Oxford Science Park Oxford Oxford United Kingdom
  582. 2600 9702 Chester Road Stretford Manchester United Kingdom
  583. 2700 Schwanthalerstr. 7031 Munich Bavaria Germany
  584. 2800 Rua Frei Caneca 1360 Sao Paulo Sao Paulo Brazil
  585. 2900 20 Rue des Corps-Saints Geneva Geneve Switzerland
  586. 3000 Murtenstrasse 921 Bern BE Switzerland
  587. 3100 Pieter Breughelstraat 837 Utrecht Utrecht Netherlands
  588. 3200 Mariano Escobedo 9991 Mexico City Distrito Federal, Mexico
  589. Argentina
  590. Israel
  591. Nigeria
  592. Egypt
  593. Kuwait
  594. France
  595. HongKong
  596. Belgium
  597. Zimbabwe
  598. Zambia
  599. Denmark
  600. 34 rows selected
  601.  
  602. Response Feedback: [None Given]
  603. Question 6
  604. Needs Grading
  605.  
  606. Display the employee id, last name, job, department name, and job grade for all employees. Should get 50+ rows.
  607.  
  608. Selected Answer:
  609. SELECT E.employee_id, E.LAST_NAME, job_id, E.SALARY, J.GRADE
  610.  
  611. FROM EMPLOYEES E JOIN JOB_GRADES J
  612.  
  613. ON E.SALARY
  614.  
  615. BETWEEN J.LOWEST_SAL AND J.HIGHEST_SAL
  616.  
  617. order by 5;
  618.  
  619.  
  620.  
  621. =====
  622.  
  623. output
  624.  
  625. =====
  626.  
  627.  
  628.  
  629.  
  630.  
  631. EMPLOYEE_ID LAST_NAME JOB_ID SALARY G
  632.  
  633. ----------- ------------------------- ---------- ---------- -
  634.  
  635. 143 Matos ST_CLERK 2600 A
  636.  
  637. 144 Vargas ST_CLERK 2500 A
  638.  
  639. 29 Loo Nam SA_REP 5500 B
  640.  
  641. 142 Davies ST_CLERK 3100 B
  642.  
  643. 19 Strandherst SA_REP 4500 B
  644.  
  645. 200 Whalen AD_ASST 4400 B
  646.  
  647. 107 Lorentz IT_PROG 4200 B
  648.  
  649. 26 LeBlanc SA_REP 3700 B
  650.  
  651. 141 Rajs ST_CLERK 3500 B
  652.  
  653. 21 Brigade SA_REP 5750 B
  654.  
  655. 124 Mourgos ST_MAN 5800 B
  656.  
  657. 17 Pallomine SA_REP 5000 B
  658.  
  659. 206 Gietz AC_ACCOUNT 8300 C
  660.  
  661. 176 Vargas SA_REP 8600 C
  662.  
  663. 8 Bergsteige SA_REP 8000 C
  664.  
  665. 23 Armarillo SA_REP 7500 C
  666.  
  667. 7 LeDuc SA_REP 7000 C
  668.  
  669. 14 Torson SA_REP 7000 C
  670.  
  671. 9 Gruber SA_REP 7000 C
  672.  
  673. 30 Chan SA_REP 7000 C
  674.  
  675. 178 Grants SA_REP 7000 C
  676.  
  677. 180 de Man SA_REP 7000 C
  678.  
  679. 33 Wandiko SA_REP 6700 C
  680.  
  681. 15 Cornel SA_REP 6500 C
  682.  
  683. 104 Ernst IT_PROG 6000 C
  684.  
  685. 202 Fay MK_REP 6000 C
  686.  
  687. 35 Krain SA_REP 8700 C
  688.  
  689. 28 Young SA_REP 9000 C
  690.  
  691. 41 Montoya SA_REP 9000 C
  692.  
  693. 40 Whiteduck SA_REP 9000 C
  694.  
  695. 103 Hunold IT_PROG 9000 C
  696.  
  697. 4 Smertal SA_REP 9000 C
  698.  
  699. 5 Mustaine SA_REP 9000 C
  700.  
  701. 34 Gregson SA_REP 8800 C
  702.  
  703. 6 Harvey SA_REP 10000 D
  704.  
  705. 25 Turcotte SA_REP 10000 D
  706.  
  707. 12 Chancevente SA_REP 12000 D
  708.  
  709. 205 Higgins AC_MGR 12000 D
  710.  
  711. 22 Litrand SA_REP 10000 D
  712.  
  713. 11 Sanchez SA_REP 10500 D
  714.  
  715. 149 Zlotkey SA_MAN 10500 D
  716.  
  717. 27 Rodriguez SA_REP 11000 D
  718.  
  719. 36 Termede SA_REP 11000 D
  720.  
  721. 174 Abel SA_REP 11000 D
  722.  
  723. 39 Testorok SA_REP 11000 D
  724.  
  725. 16 Gibbons SA_REP 11500 D
  726.  
  727. 3 Grovlin SA_REP 12000 D
  728.  
  729. 18 Jacobs SA_REP 13000 D
  730.  
  731. 201 Hartstein MK_MAN 13000 D
  732.  
  733. 1 Flertjan AC_REP 12000 D
  734.  
  735. 101 Kochhar AD_VP 17000 E
  736.  
  737. 102 De Haan AD_VP 17000 E
  738.  
  739. 100 King AD_PRES 24000 E
  740.  
  741.  
  742.  
  743. 53 rows selected.
  744.  
  745.  
  746. SELECT E.employee_id, E.LAST_NAME, job_id, E.SALARY, J.GRADE
  747. FROM EMPLOYEES E JOIN JOB_GRADES J
  748. ON E.SALARY
  749. BETWEEN J.LOWEST_SAL AND J.HIGHEST_SAL
  750. order by 5;
  751.  
  752. =====
  753. output
  754. =====
  755.  
  756.  
  757. EMPLOYEE_ID LAST_NAME JOB_ID SALARY G
  758. ----------- ------------------------- ---------- ---------- -
  759. 143 Matos ST_CLERK 2600 A
  760. 144 Vargas ST_CLERK 2500 A
  761. 29 Loo Nam SA_REP 5500 B
  762. 142 Davies ST_CLERK 3100 B
  763. 19 Strandherst SA_REP 4500 B
  764. 200 Whalen AD_ASST 4400 B
  765. 107 Lorentz IT_PROG 4200 B
  766. 26 LeBlanc SA_REP 3700 B
  767. 141 Rajs ST_CLERK 3500 B
  768. 21 Brigade SA_REP 5750 B
  769. 124 Mourgos ST_MAN 5800 B
  770. 17 Pallomine SA_REP 5000 B
  771. 206 Gietz AC_ACCOUNT 8300 C
  772. 176 Vargas SA_REP 8600 C
  773. 8 Bergsteige SA_REP 8000 C
  774. 23 Armarillo SA_REP 7500 C
  775. 7 LeDuc SA_REP 7000 C
  776. 14 Torson SA_REP 7000 C
  777. 9 Gruber SA_REP 7000 C
  778. 30 Chan SA_REP 7000 C
  779. 178 Grants SA_REP 7000 C
  780. 180 de Man SA_REP 7000 C
  781. 33 Wandiko SA_REP 6700 C
  782. 15 Cornel SA_REP 6500 C
  783. 104 Ernst IT_PROG 6000 C
  784. 202 Fay MK_REP 6000 C
  785. 35 Krain SA_REP 8700 C
  786. 28 Young SA_REP 9000 C
  787. 41 Montoya SA_REP 9000 C
  788. 40 Whiteduck SA_REP 9000 C
  789. 103 Hunold IT_PROG 9000 C
  790. 4 Smertal SA_REP 9000 C
  791. 5 Mustaine SA_REP 9000 C
  792. 34 Gregson SA_REP 8800 C
  793. 6 Harvey SA_REP 10000 D
  794. 25 Turcotte SA_REP 10000 D
  795. 12 Chancevente SA_REP 12000 D
  796. 205 Higgins AC_MGR 12000 D
  797. 22 Litrand SA_REP 10000 D
  798. 11 Sanchez SA_REP 10500 D
  799. 149 Zlotkey SA_MAN 10500 D
  800. 27 Rodriguez SA_REP 11000 D
  801. 36 Termede SA_REP 11000 D
  802. 174 Abel SA_REP 11000 D
  803. 39 Testorok SA_REP 11000 D
  804. 16 Gibbons SA_REP 11500 D
  805. 3 Grovlin SA_REP 12000 D
  806. 18 Jacobs SA_REP 13000 D
  807. 201 Hartstein MK_MAN 13000 D
  808. 1 Flertjan AC_REP 12000 D
  809. 101 Kochhar AD_VP 17000 E
  810. 102 De Haan AD_VP 17000 E
  811. 100 King AD_PRES 24000 E
  812.  
  813. 53 rows selected.
  814. Correct Answer:
  815. Correct
  816. SELECT employee_id, last_name, job_id, department_name, grade
  817.  
  818. FROM employees
  819.  
  820. LEFT JOIN departments USING (department_id)
  821.  
  822. LEFT JOIN job_grades ON (salary BETWEEN lowest_sal AND highest_sal);
  823.  
  824. NOTE: left joins required to include employees without departments or without salary since nulls are permitted for both these columns in employees table
  825.  
  826.  
  827.  
  828. Alternate Solution:
  829.  
  830. SELECT employee_id, last_name, job_id, department_name, grade
  831.  
  832. FROM departments
  833.  
  834. RIGHT JOIN employees USING (department_id)
  835.  
  836. LEFT JOIN job_grades ON (salary BETWEEN lowest_sal AND highest_sal)
  837.  
  838. Response Feedback: [None Given]
  839. Question 7
  840. Needs Grading
  841.  
  842. Display the employee id and first name of every employee along with the first name and id of the employee's manager (if applicable).
  843.  
  844. order by employee d
  845.  
  846. only show rows with employee id greater than 30 and less than 110
  847.  
  848. Selected Answer:
  849. SELECT M.employee_id as MGR#,
  850.  
  851. M.last_name AS Manager,
  852.  
  853. W.last_name AS Employee,
  854.  
  855. w.employee_id as Emp#
  856.  
  857.  
  858.  
  859. FROM employees W left JOIN employees M
  860.  
  861. ON W.manager_id = M.employee_id
  862.  
  863.  
  864.  
  865.  
  866.  
  867. where w.employee_id between 30 and 110
  868.  
  869.  
  870.  
  871. order by 4;
  872.  
  873.  
  874.  
  875. =====
  876.  
  877. output
  878.  
  879. =====
  880.  
  881. MGR# MANAGER EMPLOYEE EMP#
  882.  
  883. ---------- ------------------------- ------------------------- ----------
  884.  
  885. 149 Zlotkey Chan 30
  886.  
  887. 149 Zlotkey Wandiko 33
  888.  
  889. 149 Zlotkey Gregson 34
  890.  
  891. 149 Zlotkey Krain 35
  892.  
  893. 149 Zlotkey Termede 36
  894.  
  895. 149 Zlotkey Testorok 39
  896.  
  897. 149 Zlotkey Whiteduck 40
  898.  
  899. 149 Zlotkey Montoya 41
  900.  
  901. King 100
  902.  
  903. 100 King Kochhar 101
  904.  
  905. 100 King De Haan 102
  906.  
  907. 102 De Haan Hunold 103
  908.  
  909. 103 Hunold Ernst 104
  910.  
  911. 103 Hunold Lorentz 107
  912.  
  913.  
  914.  
  915. 14 rows selected.
  916.  
  917.  
  918. Correct Answer:
  919. Correct
  920. SELECT e.employee_id, e.first_name, m.first_name as Manager_Last_Name, m.employee_id as Manager_ID
  921. FROM employees e LEFT JOIN employees m
  922. ON (e.manager_id = m.employee_id)
  923. WHERE e.employee_id < 110
  924. and e.employee_id > 30
  925. order by e.employee_id;
  926.  
  927. EMPLOYEE_ID FIRST_NAME MANAGER_LAST_NAME MANAGER_ID
  928.  
  929. ----------- -------------------- -------------------- ----------
  930.  
  931. 33 Torey Eleni 149
  932.  
  933. 34 Kaley Eleni 149
  934.  
  935. 35 Hari Eleni 149
  936.  
  937. 36 Ingrid Eleni 149
  938.  
  939. 39 Lisa Eleni 149
  940.  
  941. 40 Marthe Eleni 149
  942.  
  943. 41 Inigo Eleni 149
  944.  
  945. 100 Steven
  946.  
  947. 101 Neena Steven 100
  948.  
  949. 102 Lex Steven 100
  950.  
  951. 103 Alexander Lex 102
  952.  
  953. 104 Bruce Alexander 103
  954.  
  955. 107 Diana Alexander 103
  956.  
  957.  
  958.  
  959. 13 rows selected
  960.  
  961. Response Feedback: [None Given]
  962. Question 8
  963. Needs Grading
  964.  
  965. Display the employee id, last name of every employee and the name of the department and city that the employee is assigned to (if applicable).
  966.  
  967.  
  968.  
  969. Selected Answer:
  970. SELECT E.Employee_id,
  971.  
  972. E.last_name,
  973.  
  974. E.job_id,
  975.  
  976. L.city
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984. FROM employees E left join Departments D
  985.  
  986. on E.department_id = D.department_id
  987.  
  988. left join Locations L
  989.  
  990. on L.location_id = D.location_id
  991.  
  992.  
  993.  
  994. order by 1;
  995.  
  996.  
  997.  
  998. ======
  999.  
  1000. output
  1001.  
  1002. ======
  1003.  
  1004. EMPLOYEE_ID LAST_NAME JOB_ID CITY
  1005.  
  1006. ----------- ------------------------- ---------- ------------------------------
  1007.  
  1008. 1 Flertjan AC_REP Seattle
  1009.  
  1010. 3 Grovlin SA_REP Oxford
  1011.  
  1012. 4 Smertal SA_REP Oxford
  1013.  
  1014. 5 Mustaine SA_REP Oxford
  1015.  
  1016. 6 Harvey SA_REP Oxford
  1017.  
  1018. 7 LeDuc SA_REP Oxford
  1019.  
  1020. 8 Bergsteige SA_REP Oxford
  1021.  
  1022. 9 Gruber SA_REP Oxford
  1023.  
  1024. 11 Sanchez SA_REP Oxford
  1025.  
  1026. 12 Chancevente SA_REP Oxford
  1027.  
  1028. 14 Torson SA_REP Oxford
  1029.  
  1030. 15 Cornel SA_REP Oxford
  1031.  
  1032. 16 Gibbons SA_REP Oxford
  1033.  
  1034. 17 Pallomine SA_REP Oxford
  1035.  
  1036. 18 Jacobs SA_REP Oxford
  1037.  
  1038. 19 Strandherst SA_REP Oxford
  1039.  
  1040. 21 Brigade SA_REP Oxford
  1041.  
  1042. 22 Litrand SA_REP Oxford
  1043.  
  1044. 23 Armarillo SA_REP Oxford
  1045.  
  1046. 24 Mot SA_REP Oxford
  1047.  
  1048. 25 Turcotte SA_REP Oxford
  1049.  
  1050. 26 LeBlanc SA_REP Oxford
  1051.  
  1052. 27 Rodriguez SA_REP Oxford
  1053.  
  1054. 28 Young SA_REP Oxford
  1055.  
  1056. 29 Loo Nam SA_REP Oxford
  1057.  
  1058. 30 Chan SA_REP Oxford
  1059.  
  1060. 33 Wandiko SA_REP Oxford
  1061.  
  1062. 34 Gregson SA_REP Oxford
  1063.  
  1064. 35 Krain SA_REP Oxford
  1065.  
  1066. 36 Termede SA_REP Oxford
  1067.  
  1068. 39 Testorok SA_REP Oxford
  1069.  
  1070. 40 Whiteduck SA_REP Oxford
  1071.  
  1072. 41 Montoya SA_REP Oxford
  1073.  
  1074. 100 King AD_PRES Seattle
  1075.  
  1076. 101 Kochhar AD_VP Seattle
  1077.  
  1078. 102 De Haan AD_VP Seattle
  1079.  
  1080. 103 Hunold IT_PROG Southlake
  1081.  
  1082. 104 Ernst IT_PROG Southlake
  1083.  
  1084. 107 Lorentz IT_PROG Southlake
  1085.  
  1086. 124 Mourgos ST_MAN south San Francisco
  1087.  
  1088. 141 Rajs ST_CLERK south San Francisco
  1089.  
  1090. 142 Davies ST_CLERK south San Francisco
  1091.  
  1092. 143 Matos ST_CLERK south San Francisco
  1093.  
  1094. 144 Vargas ST_CLERK south San Francisco
  1095.  
  1096. 149 Zlotkey SA_MAN Oxford
  1097.  
  1098. 174 Abel SA_REP Oxford
  1099.  
  1100. 176 Vargas SA_REP Oxford
  1101.  
  1102. 178 Grants SA_REP
  1103.  
  1104. 180 de Man SA_REP
  1105.  
  1106. 200 Whalen AD_ASST Seattle
  1107.  
  1108. 201 Hartstein MK_MAN Toronto
  1109.  
  1110. 202 Fay MK_REP Toronto
  1111.  
  1112. 205 Higgins AC_MGR Seattle
  1113.  
  1114. 206 Gietz AC_ACCOUNT Seattle
  1115.  
  1116.  
  1117.  
  1118. 54 rows selected.
  1119.  
  1120.  
  1121. Correct Answer:
  1122. Correct
  1123. SELECT employee_id, last_name, department_name, city
  1124.  
  1125. FROM employees
  1126.  
  1127. LEFT JOIN departments using (department_id)
  1128.  
  1129. LEFT JOIN locations using (location_id);
  1130.  
  1131. Response Feedback: [None Given]
  1132. Question 9
  1133. Needs Grading
  1134.  
  1135. Display the name of each city and the names of employees assigned to that city (if applicable).
  1136.  
  1137. Selected Answer:
  1138. SELECT E.first_name,
  1139.  
  1140. E.last_name,
  1141.  
  1142. L.city
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150. FROM employees E left join Departments D
  1151.  
  1152. on E.department_id = D.department_id
  1153.  
  1154. left join Locations L
  1155.  
  1156. on L.location_id = D.location_id
  1157.  
  1158.  
  1159.  
  1160. order by 1;
  1161.  
  1162.  
  1163.  
  1164. =====
  1165.  
  1166. output
  1167.  
  1168. =====
  1169.  
  1170. FIRST_NAME LAST_NAME CITY
  1171.  
  1172. -------------------- ------------------------- ------------------------------
  1173.  
  1174. Alexander Hunold Southlake
  1175.  
  1176. Bil Gibbons Oxford
  1177.  
  1178. Bill Smertal Oxford
  1179.  
  1180. Bjorn Flertjan Seattle
  1181.  
  1182. Bruce Ernst Southlake
  1183.  
  1184. Carlos Rodriguez Oxford
  1185.  
  1186. Charles Loo Nam Oxford
  1187.  
  1188. Chris Cornel Oxford
  1189.  
  1190. Conrad Bergsteige Oxford
  1191.  
  1192. Curtis Davies south San Francisco
  1193.  
  1194. Dan Chancevente Oxford
  1195.  
  1196. Dave Mustaine Oxford
  1197.  
  1198. Diana Lorentz Southlake
  1199.  
  1200. Eleni Zlotkey Oxford
  1201.  
  1202. Ellen Abel Oxford
  1203.  
  1204. Francoise LeBlanc Oxford
  1205.  
  1206. Gilles Turcotte Oxford
  1207.  
  1208. Greg Torson Oxford
  1209.  
  1210. Gus Grovlin Oxford
  1211.  
  1212. Hari Krain Oxford
  1213.  
  1214. Henri LeDuc Oxford
  1215.  
  1216. Henry Harvey Oxford
  1217.  
  1218. Ingrid Termede Oxford
  1219.  
  1220. Inigo Montoya Oxford
  1221.  
  1222. Jane Litrand Oxford
  1223.  
  1224. Jennifer Whalen Seattle
  1225.  
  1226. Jonathon Vargas Oxford
  1227.  
  1228. Kaley Gregson Oxford
  1229.  
  1230. Kevin Mourgos south San Francisco
  1231.  
  1232. Kimberely Grants
  1233.  
  1234. Kurt Gruber Oxford
  1235.  
  1236. Lee Chan Oxford
  1237.  
  1238. Lex De Haan Seattle
  1239.  
  1240. Lisa Testorok Oxford
  1241.  
  1242. Lyn Jacobs Oxford
  1243.  
  1244. Malcom Young Oxford
  1245.  
  1246. Marthe Whiteduck Oxford
  1247.  
  1248. Matt Mot Oxford
  1249.  
  1250. Michael Hartstein Toronto
  1251.  
  1252. Miguel Sanchez Oxford
  1253.  
  1254. Neena Kochhar Seattle
  1255.  
  1256. Pat Fay Toronto
  1257.  
  1258. Peter Vargas south San Francisco
  1259.  
  1260. Randall Matos south San Francisco
  1261.  
  1262. Russ Pallomine Oxford
  1263.  
  1264. Sally Strandherst Oxford
  1265.  
  1266. Shelley Higgins Seattle
  1267.  
  1268. Spence de Man
  1269.  
  1270. Steven King Seattle
  1271.  
  1272. Thomas Brigade Oxford
  1273.  
  1274. Tony Armarillo Oxford
  1275.  
  1276. Torey Wandiko Oxford
  1277.  
  1278. Trenna Rajs south San Francisco
  1279.  
  1280. William Gietz Seattle
  1281.  
  1282.  
  1283.  
  1284. 54 rows selected.
  1285.  
  1286.  
  1287. Correct Answer:
  1288. Correct
  1289. Means show every city and if an employee is associated with the city then show the employee also. Means it is likely there are cities without employees;
  1290.  
  1291. SELECT city, last_name, first_name
  1292.  
  1293. FROM locations
  1294.  
  1295. LEFT JOIN departments USING (location_id)
  1296.  
  1297. LEFT JOIN employees USING (department_id);
  1298.  
  1299.  
  1300. 73 rows. The last ones look like this showing cities and no employees
  1301.  
  1302.  
  1303. Oxford Turcotte Gilles
  1304. Oxford Vargas Jonathon
  1305. south San Francisco Vargas Peter
  1306. Oxford Wandiko Torey
  1307. Seattle Whalen Jennifer
  1308. Oxford Whiteduck Marthe
  1309. Oxford Young Malcom
  1310. Oxford Zlotkey Eleni
  1311. Munich
  1312. Mexico City
  1313. Roma
  1314. Stretford
  1315. Hiroshima
  1316. Singapore
  1317. Whitehorse
  1318. Venice
  1319. Sao Paulo
  1320. Geneva
  1321. Bombay
  1322. South Brunswick
  1323. Utrecht
  1324. Sydney
  1325. Tokyo
  1326. London
  1327. Bern
  1328. Beijing
  1329. Seattle
  1330. Seattle
  1331. 73 rows selected
  1332.  
  1333. Response Feedback: [None Given]
  1334. Question 10
  1335. Needs Grading
  1336.  
  1337. Display all employees and all cities.
  1338.  
  1339. Selected Answer:
  1340. SELECT first_name || last_name as Employee, city
  1341.  
  1342.  
  1343.  
  1344. FROM employees
  1345.  
  1346.  
  1347.  
  1348. FULL JOIN departments using (department_id)
  1349.  
  1350. FULL JOIN locations using (location_id);
  1351.  
  1352.  
  1353.  
  1354. ======
  1355.  
  1356. output
  1357.  
  1358. ======
  1359.  
  1360.  
  1361.  
  1362. EMPLOYEE CITY
  1363.  
  1364. --------------------------------------------- ------------------------------
  1365.  
  1366. StevenKing Seattle
  1367.  
  1368. NeenaKochhar Seattle
  1369.  
  1370. LexDe Haan Seattle
  1371.  
  1372. AlexanderHunold Southlake
  1373.  
  1374. BruceErnst Southlake
  1375.  
  1376. DianaLorentz Southlake
  1377.  
  1378. KevinMourgos south San Francisco
  1379.  
  1380. TrennaRajs south San Francisco
  1381.  
  1382. CurtisDavies south San Francisco
  1383.  
  1384. RandallMatos south San Francisco
  1385.  
  1386. PeterVargas south San Francisco
  1387.  
  1388. EleniZlotkey Oxford
  1389.  
  1390. EllenAbel Oxford
  1391.  
  1392. JonathonVargas Oxford
  1393.  
  1394. KimberelyGrants
  1395.  
  1396. Spencede Man
  1397.  
  1398. JenniferWhalen Seattle
  1399.  
  1400. MichaelHartstein Toronto
  1401.  
  1402. PatFay Toronto
  1403.  
  1404. ShelleyHiggins Seattle
  1405.  
  1406. WilliamGietz Seattle
  1407.  
  1408. BjornFlertjan Seattle
  1409.  
  1410. GusGrovlin Oxford
  1411.  
  1412. BillSmertal Oxford
  1413.  
  1414. DaveMustaine Oxford
  1415.  
  1416. HenryHarvey Oxford
  1417.  
  1418. HenriLeDuc Oxford
  1419.  
  1420. ConradBergsteige Oxford
  1421.  
  1422. KurtGruber Oxford
  1423.  
  1424. MiguelSanchez Oxford
  1425.  
  1426. DanChancevente Oxford
  1427.  
  1428. GregTorson Oxford
  1429.  
  1430. ChrisCornel Oxford
  1431.  
  1432. BilGibbons Oxford
  1433.  
  1434. RussPallomine Oxford
  1435.  
  1436. LynJacobs Oxford
  1437.  
  1438. SallyStrandherst Oxford
  1439.  
  1440. ThomasBrigade Oxford
  1441.  
  1442. JaneLitrand Oxford
  1443.  
  1444. TonyArmarillo Oxford
  1445.  
  1446. MattMot Oxford
  1447.  
  1448. GillesTurcotte Oxford
  1449.  
  1450. FrancoiseLeBlanc Oxford
  1451.  
  1452. CarlosRodriguez Oxford
  1453.  
  1454. MalcomYoung Oxford
  1455.  
  1456. CharlesLoo Nam Oxford
  1457.  
  1458. LeeChan Oxford
  1459.  
  1460. ToreyWandiko Oxford
  1461.  
  1462. KaleyGregson Oxford
  1463.  
  1464. HariKrain Oxford
  1465.  
  1466. IngridTermede Oxford
  1467.  
  1468. LisaTestorok Oxford
  1469.  
  1470. MartheWhiteduck Oxford
  1471.  
  1472. InigoMontoya Oxford
  1473.  
  1474. Seattle
  1475.  
  1476. Seattle
  1477.  
  1478. Beijing
  1479.  
  1480. Bern
  1481.  
  1482. London
  1483.  
  1484. Tokyo
  1485.  
  1486. Sydney
  1487.  
  1488. Utrecht
  1489.  
  1490. South Brunswick
  1491.  
  1492. Bombay
  1493.  
  1494. Geneva
  1495.  
  1496. Sao Paulo
  1497.  
  1498. Venice
  1499.  
  1500. Whitehorse
  1501.  
  1502. Singapore
  1503.  
  1504. Hiroshima
  1505.  
  1506. Stretford
  1507.  
  1508. Roma
  1509.  
  1510. Mexico City
  1511.  
  1512. Munich
  1513.  
  1514.  
  1515.  
  1516. 74 rows selected.
  1517.  
  1518.  
  1519. Correct Answer:
  1520. Correct
  1521. SELECT city, employee_id, last_name, first_name
  1522.  
  1523. FROM employees
  1524.  
  1525. FULL JOIN departments using (department_id)
  1526.  
  1527. FULL JOIN locations using (location_id);
  1528.  
  1529.  
  1530.  
  1531. NOTE: full joins (left and right) required since some employees do not have location_ids and some locations may not have country_id and some countries do not have locations and some locations do not have employees
  1532.  
  1533.  
  1534.  
  1535. Response Feedback: [N
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement