Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.54 KB | None | 0 0
  1. Question 1
  2. Needs Grading
  3.  
  4. Remember you need te SQL and the resulting output to get any marks.
  5.  
  6. SET PAGESIZE 200 also
  7.  
  8. Execute he following command
  9.  
  10. SET AUTOCOMMIT ON (do this each time you log on for this lab) so any updates, deletes and inserts are automatically committed before you exit from Oracle.
  11.  
  12. When done answer YES in the answer section
  13.  
  14.  
  15.  
  16. Selected Answer:
  17. yes
  18.  
  19. Correct Answer:
  20. Correct
  21. YES should appear as the answer to doing it
  22.  
  23. Response Feedback: [None Given]
  24. Question 2
  25. Needs Grading
  26.  
  27. Did you read the previous instructions about auto commit.
  28.  
  29.  
  30. Change the following insert
  31.  
  32.  
  33. (1) make sure you exist as an employee (2) with a NULL salary and (3) 0.2 commission_pct (4)in department 90 and (5) your email.
  34.  
  35.  
  36. Leave the rest as is
  37.  
  38.  
  39.  
  40. INSERT INTO EMPLOYEES
  41. VALUES
  42. (777,'Ron','Tarr','youremail','123.123.1234',
  43. '31-DEC-99','IT_PROG', 22000,.15,102,90);
  44.  
  45. Selected Answer:
  46. INSERT INTO employees
  47.  
  48. VALUES
  49.  
  50. (777, 'Ethan', 'Johnson', 'ejohnson16@myseneca.ca', '123.123.1234', SYSDATE, 'IT_PROG', NULL, 0.2, 102, 90);
  51.  
  52.  
  53. Correct Answer:
  54. Correct
  55.  
  56. INSERT INTO EMPLOYEES
  57. VALUES
  58. (777,'Ron','Tarr','youremail','123.123.1234',
  59. '31-DEC-99','IT_PROG',NULL,.2,102,90);
  60.  
  61. Response Feedback: [None Given]
  62. Question 3
  63. Needs Grading
  64.  
  65. YOU MUST USE SUBQUERIES for these questions.
  66.  
  67. (Must also minimize the number of tables when answering. Example don't use 10 tables when 3 will do)
  68.  
  69. Display the last names of all employees who are in the same department as the employee named who has a name called CHan.
  70.  
  71. You are NOT asked to prompt the user, but make the SQL flexible as though a user will enter any case.
  72.  
  73. Alphabetical order from A to Z
  74.  
  75. Selected Answer:
  76. SELECT last_name AS "Last Name"
  77.  
  78. FROM employees
  79.  
  80. WHERE department_id =
  81.  
  82. (SELECT department_id
  83.  
  84. FROM employees
  85.  
  86. WHERE UPPER(last_name) = 'CHAN')
  87.  
  88. ORDER BY 1 ASC;
  89.  
  90.  
  91. =====
  92.  
  93. output
  94.  
  95. =====
  96.  
  97. Last Name
  98.  
  99. -------------------------
  100.  
  101. Abel
  102.  
  103. Armarillo
  104.  
  105. Bergsteige
  106.  
  107. Brigade
  108.  
  109. Chan
  110.  
  111. Chancevente
  112.  
  113. Cornel
  114.  
  115. Gibbons
  116.  
  117. Gregson
  118.  
  119. Grovlin
  120.  
  121. Gruber
  122.  
  123. Harvey
  124.  
  125. Jacobs
  126.  
  127. Krain
  128.  
  129. LeBlanc
  130.  
  131. LeDuc
  132.  
  133. Litrand
  134.  
  135. Loo Nam
  136.  
  137. Montoya
  138.  
  139. Mot
  140.  
  141. Mustaine
  142.  
  143. Pallomine
  144.  
  145. Rodriguez
  146.  
  147. Sanchez
  148.  
  149. Smertal
  150.  
  151. Strandherst
  152.  
  153. Termede
  154.  
  155. Testorok
  156.  
  157. Torson
  158.  
  159. Turcotte
  160.  
  161. Vargas
  162.  
  163. Wandiko
  164.  
  165. Whiteduck
  166.  
  167. Young
  168.  
  169. Zlotkey
  170.  
  171.  
  172.  
  173. 35 rows selected.
  174.  
  175.  
  176. Correct Answer:
  177. Correct
  178. select last_name
  179. from employees
  180. where department_id = (select department_id
  181. from employees
  182. where UPPER(last_name) = UPPER('CHan')
  183. )
  184. order by last_name;
  185.  
  186.  
  187.  
  188.  
  189.  
  190. LAST_NAME
  191. -------------------------
  192. Abel
  193. Armarillo
  194. Bergsteige
  195. Brigade
  196. Chan
  197. Chancevente
  198. Cornel
  199. Gibbons
  200. Gregson
  201. Grovlin
  202. Gruber
  203. Harvey
  204. Jacobs
  205. Krain
  206. LeBlanc
  207. LeDuc
  208. Litrand
  209. Loo Nam
  210. Montoya
  211. Mot
  212. Mustaine
  213. Pallomine
  214. Rodriguez
  215. Sanchez
  216. Smertal
  217. Strandherst
  218. Termede
  219. Testorok
  220. Torson
  221. Turcotte
  222. Vargas
  223. Wandiko
  224. Whiteduck
  225. Young
  226. Zlotkey
  227.  
  228. 35 rows selected
  229. Response Feedback: [None Given]
  230. Question 4
  231. Needs Grading
  232.  
  233. Display the last name then first name of the lowest paid employee(s)
  234.  
  235. Selected Answer:
  236. select last_name, first_name
  237.  
  238. from employees
  239.  
  240. where salary = (select min(salary)
  241.  
  242. from employees);
  243.  
  244. =====
  245.  
  246. output
  247.  
  248. ======
  249.  
  250.  
  251. LAST_NAME FIRST_NAME
  252.  
  253. ------------------------- --------------------
  254.  
  255. Vargas Peter
  256.  
  257. Correct Answer:
  258. Correct
  259. LAST_NAME FIRST_NAME
  260.  
  261. ------------------------- --------------------
  262.  
  263. Vargas Peter
  264.  
  265. SELECT LAST_NAME as "Last Name"
  266.  
  267. FROM EMPLOYEES
  268.  
  269. WHERE SALARY =
  270.  
  271. (SELECT MIN(SALARY)
  272.  
  273. FROM EMPLOYEES);
  274.  
  275. Response Feedback: [None Given]
  276. Question 5
  277. Needs Grading
  278.  
  279. Change the salary of the both employees with a last name of Matos and Whalen to be 2500.
  280.  
  281. Selected Answer:
  282. update employees
  283.  
  284. set salary = 2500
  285.  
  286. where upper(last_name) = 'MATOS' or upper(last_name) = 'WHALEN' ;
  287.  
  288.  
  289. =====
  290.  
  291. OUTPUT
  292.  
  293. =====
  294.  
  295. 2 rows updated.
  296. Commit complete.
  297.  
  298. Correct Answer:
  299. Correct
  300. UPDATE EMPLOYEES
  301.  
  302. SET SALARY = 2500
  303.  
  304. WHERE LAST_NAME = 'Matos' OR LAST_NAME = 'Whalen';
  305.  
  306. Response Feedback: [None Given]
  307. Question 6
  308. Needs Grading
  309.  
  310. Display the city that the lowest paid employee(s) are located in.
  311.  
  312. Selected Answer:
  313. SELECT city
  314.  
  315. FROM locations
  316.  
  317. WHERE location_id IN (
  318.  
  319. SELECT location_id
  320.  
  321. FROM departments
  322.  
  323. WHERE department_id IN (
  324.  
  325. SELECT department_id
  326.  
  327. FROM employees
  328.  
  329. WHERE salary = (
  330.  
  331. SELECT MIN(salary)
  332.  
  333. FROM employees)));
  334.  
  335.  
  336. ======
  337.  
  338. output
  339.  
  340. ======
  341.  
  342.  
  343. CITY
  344.  
  345. ------------------------------
  346.  
  347. south San Francisco
  348.  
  349. Seattle
  350.  
  351.  
  352. Correct Answer:
  353. Correct
  354. SELECT DISTICT CITY,
  355.  
  356. FROM LOCATIONS JOIN DEPARTMENTS USING (LOCATION_ID) JOIN
  357.  
  358. EMPLOYEES USING (DEPARTMENT_ID)
  359.  
  360. WHERE SALARY =
  361.  
  362. (SELECT MIN(SALARY) FROM EMPLOYEES);
  363.  
  364. CITY
  365.  
  366. ------------------------------
  367.  
  368. South San Francisco
  369.  
  370.  
  371. also Seattle
  372.  
  373. Response Feedback: [None Given]
  374. Question 7
  375. Needs Grading
  376.  
  377. Display the last name of the lowest paid employee(s) in each department
  378.  
  379. Selected Answer:
  380.  
  381. select last_name, DEPARTMENT_ID
  382.  
  383. from employees
  384.  
  385. where (department_id, salary) in
  386.  
  387. (select department_id, min(salary)
  388.  
  389. from employees
  390.  
  391. group by department_id);
  392.  
  393.  
  394. =====
  395.  
  396. OUTPUT
  397.  
  398. ======
  399.  
  400. LAST_NAME DEPARTMENT_ID
  401.  
  402. ------------------------- -------------
  403.  
  404. De Haan 90
  405.  
  406. Kochhar 90
  407.  
  408. Fay 20
  409.  
  410. Gietz 110
  411.  
  412. Vargas 50
  413.  
  414. Matos 50
  415.  
  416. LeBlanc 80
  417.  
  418. Lorentz 60
  419.  
  420. Whalen 10
  421.  
  422.  
  423.  
  424. 9 rows selected.
  425.  
  426.  
  427. Correct Answer:
  428. Correct
  429. SELECT LAST_NAME
  430.  
  431. FROM EMPLOYEES
  432.  
  433. WHERE SALARY IN
  434.  
  435. (SELECT MIN(SALARY)
  436.  
  437. FROM EMPLOYEES
  438.  
  439. GROUP BY DEPARTMENT_ID);
  440.  
  441.  
  442. This answer does not take into account an employee in another department that is not the minimum but matches the minimum.
  443.  
  444. Need to pass back 2 items from subquery. See what happens when I added 2 more columns to understand the output better.
  445.  
  446. WHERE (DEPARMENT_ID, SALARY) IN ... DON'T FORGET TO BRACKET
  447.  
  448. (SELECT DEPARTMENT_ID, MIN(SALARY)
  449.  
  450.  
  451.  
  452. LAST_NAME DEPARTMENT_ID SALARY
  453. ------------------------- ------------- ----------
  454. Kochhar 90 17000
  455. De Haan 90 17000
  456. Ernst 60 6000
  457. Lorentz 60 4200
  458. Matos 50 2500
  459. Vargas 50 2500
  460. Grants 7000
  461. de Man 7000
  462. Whalen 10 2500
  463. Fay 20 6000
  464. Gietz 110 8300
  465. LeDuc 80 7000
  466. Gruber 80 7000
  467. Torson 80 7000
  468. LeBlanc 80 3700 who is the lowest????
  469. Chan 80 7000
  470.  
  471. 16 rows selected
  472. Response Feedback: [None Given]
  473. Question 8
  474. Needs Grading
  475.  
  476. Display the last name of the lowest paid employee(s) in each city
  477.  
  478. Selected Answer:
  479. SELECT city,last_name, salary
  480.  
  481. FROM (
  482.  
  483. SELECT city, last_name, salary
  484.  
  485. FROM (employees e JOIN departments d
  486.  
  487. ON e.department_id=d.department_id) JOIN locations l
  488.  
  489. ON d.location_id=l.location_id
  490.  
  491. )
  492.  
  493. WHERE city||salary IN (
  494.  
  495. SELECT city || MIN(salary)
  496.  
  497. FROM (employees e JOIN departments d
  498.  
  499. ON e.department_id=d.department_id) JOIN locations l
  500.  
  501. ON d.location_id=l.location_id
  502.  
  503. GROUP BY city
  504.  
  505. );
  506.  
  507.  
  508. =====
  509.  
  510. output
  511.  
  512. =====
  513.  
  514.  
  515. CITY LAST_NAME SALARY
  516.  
  517. ------------------------------ ------------------------- ----------
  518.  
  519. Seattle Whalen 2500
  520.  
  521. south San Francisco Matos 2500
  522.  
  523. south San Francisco Vargas 2500
  524.  
  525. Toronto Fay 6000
  526.  
  527. Southlake Lorentz 4200
  528.  
  529. Oxford LeBlanc 3700
  530.  
  531.  
  532.  
  533. 6 rows selected.
  534.  
  535. Correct Answer:
  536. Correct
  537. SELECT LAST_NAME
  538.  
  539. FROM EMPLOYEES
  540.  
  541. WHERE SALARY IN
  542.  
  543. (SELECT MIN(SALARY)
  544.  
  545. FROM LOCATIONS JOIN DEPARTMENTS USING (LOCATION_ID)
  546.  
  547. JOIN EMPLOYEES USING (DEPARTMENT_ID)
  548.  
  549. GROUP BY CITY);
  550.  
  551. LAST_NAME
  552.  
  553. -------------------------
  554.  
  555. Ernst
  556.  
  557. Lorentz
  558.  
  559. Vargas
  560.  
  561. Grants
  562.  
  563. de Man
  564.  
  565. Whalen
  566.  
  567. Fay
  568.  
  569. LeDuc
  570.  
  571.  
  572.  
  573. Response Feedback: [None Given]
  574. Question 9
  575. Needs Grading
  576.  
  577. Display last name and salary for all employees who earn less than the lowest salary in ANY department.
  578.  
  579. Sort the output by top salaries first and then by last name.
  580.  
  581. Selected Answer:
  582. select last_name, salary
  583.  
  584. from employees
  585.  
  586. WHERE salary < ANY(
  587.  
  588. SELECT MIN(salary)
  589.  
  590. FROM employees
  591.  
  592. GROUP BY department_id
  593.  
  594. )
  595.  
  596. order by 2 desc, 1
  597.  
  598.  
  599. =====
  600.  
  601. output
  602.  
  603. =====
  604.  
  605. LAST_NAME SALARY
  606.  
  607. ------------------------- ----------
  608.  
  609. Hartstein 13000
  610.  
  611. Jacobs 13000
  612.  
  613. Chancevente 12000
  614.  
  615. Flertjan 12000
  616.  
  617. Grovlin 12000
  618.  
  619. Higgins 12000
  620.  
  621. Gibbons 11500
  622.  
  623. Abel 11000
  624.  
  625. Rodriguez 11000
  626.  
  627. Termede 11000
  628.  
  629. Testorok 11000
  630.  
  631. Sanchez 10500
  632.  
  633. Zlotkey 10500
  634.  
  635. Harvey 10000
  636.  
  637. Litrand 10000
  638.  
  639. Turcotte 10000
  640.  
  641. Hunold 9000
  642.  
  643. Montoya 9000
  644.  
  645. Mustaine 9000
  646.  
  647. Smertal 9000
  648.  
  649. Whiteduck 9000
  650.  
  651. Young 9000
  652.  
  653. Gregson 8800
  654.  
  655. Krain 8700
  656.  
  657. Vargas 8600
  658.  
  659. Gietz 8300
  660.  
  661. Bergsteige 8000
  662.  
  663. Armarillo 7500
  664.  
  665. Chan 7000
  666.  
  667. Grants 7000
  668.  
  669. Gruber 7000
  670.  
  671. LeDuc 7000
  672.  
  673. Torson 7000
  674.  
  675. de Man 7000
  676.  
  677. Wandiko 6700
  678.  
  679. Cornel 6500
  680.  
  681. Ernst 6000
  682.  
  683. Fay 6000
  684.  
  685. Mourgos 5800
  686.  
  687. Brigade 5750
  688.  
  689. Loo Nam 5500
  690.  
  691. Pallomine 5000
  692.  
  693. Strandherst 4500
  694.  
  695. Lorentz 4200
  696.  
  697. LeBlanc 3700
  698.  
  699. Rajs 3500
  700.  
  701. Davies 3100
  702.  
  703. Matos 2500
  704.  
  705. Vargas 2500
  706.  
  707. Whalen 2500
  708.  
  709.  
  710.  
  711. 50 rows selected.
  712.  
  713.  
  714. Correct Answer:
  715. Correct
  716. SELECT last_name, salary
  717.  
  718. FROM employees
  719.  
  720. WHERE salary < ANY (
  721.  
  722. SELECT MIN(salary)
  723.  
  724. FROM employees
  725.  
  726. GROUP BY department_id
  727.  
  728. )
  729.  
  730. ORDER BY salary DESC, last_name;
  731.  
  732.  
  733.  
  734. LAST_NAME SALARY
  735.  
  736. ------------------------- ----------
  737.  
  738. Hartstein 13000
  739.  
  740. Chancevente 12000
  741.  
  742. Higgins 12000
  743.  
  744. Abel 11000
  745.  
  746. Armarillo 11000
  747.  
  748. Brigade 11000
  749.  
  750. Chan 11000
  751.  
  752. Cornel 11000
  753.  
  754. Flertjan 11000
  755.  
  756. Gibbons 11000
  757.  
  758. Gregson 11000
  759.  
  760. Grovlin 11000
  761.  
  762. Jacobs 11000
  763.  
  764. Krain 11000
  765.  
  766. LeBlanc 11000
  767.  
  768. Loo Nam 11000
  769.  
  770. Montoya 11000
  771.  
  772. Mot 11000
  773.  
  774. Mustaine 11000
  775.  
  776. Pallomine 11000
  777.  
  778. Rodriguez 11000
  779.  
  780. Sanchez 11000
  781.  
  782. Smertal 11000
  783.  
  784. Termede 11000
  785.  
  786. Testorok 11000
  787.  
  788. Torson 11000
  789.  
  790. Turcotte 11000
  791.  
  792. Wandiko 11000
  793.  
  794. Whiteduck 11000
  795.  
  796. Zlotkey 10500
  797.  
  798. Harvey 10000
  799.  
  800. Litrand 10000
  801.  
  802. Young 10000
  803.  
  804. Gruber 9000
  805.  
  806. Hunold 9000
  807.  
  808. Strandherst 9000
  809.  
  810. Taylor 8600
  811.  
  812. Gietz 8300
  813.  
  814. Bergsteige 8000
  815.  
  816. Grants 7000
  817.  
  818. LeDuc 7000
  819.  
  820. de Man 7000
  821.  
  822. Ernst 6000
  823.  
  824. Fay 6000
  825.  
  826. Mourgos 5800
  827.  
  828. Whalen 4400
  829.  
  830. Lorentz 4200
  831.  
  832. Rajs 3500
  833.  
  834. Davies 3100
  835.  
  836. Matos 2600
  837.  
  838. Vargas 2500
  839.  
  840.  
  841.  
  842. 51 rows selected
  843.  
  844.  
  845. Response Feedback: [None Given]
  846. Question 10
  847. Needs Grading
  848.  
  849. Display last name, job title and salary for all employees whose salary matches any of the salaries from the IT Department.
  850.  
  851. Do NOT use Join method.
  852.  
  853. Sort the output by salary ascending first and then by last_name
  854.  
  855. Selected Answer:
  856.  
  857.  
  858. SELECT last_name
  859.  
  860. job_id,
  861.  
  862. salary
  863.  
  864. FROM employees
  865.  
  866. WHERE salary = ANY(
  867.  
  868. SELECT salary
  869.  
  870. FROM employees
  871.  
  872. WHERE department_id = (
  873.  
  874. SELECT department_id
  875.  
  876. FROM departments
  877.  
  878. WHERE UPPER(department_name)='IT'
  879.  
  880. )
  881.  
  882. )
  883.  
  884. ORDER BY salary, last_name;
  885.  
  886.  
  887. =====
  888.  
  889. output
  890.  
  891. =====
  892.  
  893. JOB_ID SALARY
  894.  
  895. ------------------------- ----------
  896.  
  897. Lorentz 4200
  898.  
  899. Ernst 6000
  900.  
  901. Fay 6000
  902.  
  903. Hunold 9000
  904.  
  905. Montoya 9000
  906.  
  907. Mustaine 9000
  908.  
  909. Smertal 9000
  910.  
  911. Whiteduck 9000
  912.  
  913. Young 9000
  914.  
  915.  
  916.  
  917. 9 rows selected.
  918.  
  919.  
  920. Correct Answer:
  921. Correct
  922. SELECT last_name, job_id, salary
  923.  
  924. FROM employees
  925.  
  926. WHERE salary = ANY (
  927.  
  928. SELECT salary
  929.  
  930. FROM employees
  931.  
  932. WHERE job_id = 'IT_PROG'
  933.  
  934. )
  935.  
  936. ORDER BY salary, last_name;
  937.  
  938. LAST_NAME JOB_ID SALARY
  939.  
  940. ------------------------- ---------- ----------
  941.  
  942. Lorentz IT_PROG 4200
  943.  
  944. Ernst IT_PROG 6000
  945.  
  946. Fay MK_REP 6000
  947.  
  948. Gruber SA_REP 9000
  949.  
  950. Hunold IT_PROG 9000
  951.  
  952. Strandherst SA_REP 9000
  953.  
  954.  
  955. NOTE: Did we really want to include those from IT as well
  956.  
  957.  
  958.  
  959. 6 rows selected
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement