Advertisement
rahulkondawise

mysql prob1 and 2

Mar 27th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.09 KB | None | 0 0
  1. Problem 1: Using Case in statement
  2. Solution:
  3. 1)  set salary = case
  4.                         when name = “Dr. Crazy” then salary * 1.6
  5.                                       else salary * 1.1
  6.                                       end
  7.  
  8. 2)  set salary = if(name = “Dr. Crazy” , salary * 1.6, salary * 1.1)
  9.  
  10.  ref:http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html
  11. problem 2:
  12. (a) What is query 1 seeking?
  13. Solution:
  14. To get all student Ids and student names, without duplicates who take any course and belong to biology department.
  15. Innermost query gives course ids of students who belong to biology. For this except is applied and so we have course ids of all who take except of whom don’t belong to biology dept. to this not exists is applied, which gives the students who take any course who only belong to biology dept.
  16.  
  17. (b) What is query 2 seeking?
  18. Solution:
  19. To get all student ids and names, without duplicates who take any course and belong to any department.
  20. Innermost query gives student ids who are taking any course in any department. To this except is applied giving curse ids of none. So, if not exists is applied to this, it gives course all course ids, which gives all student ids and names.
  21.  
  22. (c) What is query 3 seeking?
  23. Solution:
  24. To get all student Ids and student names, without duplicates who take any course but doesn`t belong to biology department.
  25.  
  26. Innermost query gives course ids of students who belong to biology. For this except is applied and so we have course ids of all who take except of whom don’t belong to biology dept.
  27.  
  28. (d) What is query 4 seeking?
  29.  
  30. Solution:
  31. To get student ids and names of none.
  32.  
  33. Innermost query gives student ids who are taking any course in any department. To this except is applied giving curse ids of none.
  34.  
  35. (e) If I want to use query 4 to express query 2 with the help of another except, how would you rewrite query 4?
  36. (f) Same as above but for query 1 and 3 but think about the following before you translate it by brute force: Can you or cannot you do the same trick to express query 1 in terms of query 3? And why?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement