Advertisement
Guest User

xddd

a guest
Jan 27th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1.  
  2.  
  3. --show occupied hours at which there was no visit(management wants to check if the number is not too high)
  4. SELECT Work_shift.Id as workShiftID, Work_shift.Day_of_the_week as dayOfTheWeek,
  5. (SELECT COUNT(*) FROM Occupied_hours WHERE Occupied_hours.Id not in(SELECT Visits.Occupied_hours_id FROM Visits)) as nrOfHoursWithNoVisits
  6. FROM Work_shift, Occupied_hours, Visits
  7. WHERE Occupied_hours.Id not in (SELECT Visits.Occupied_hours_id FROM Visits)
  8. GROUP BY Work_shift.Id, Work_shift.Day_of_the_week
  9. ORDER BY 1
  10.  
  11. --show all services with amount amount of money that was made from them in total(want to check which one is the most profitable)
  12. SELECT Service_made_AND_Price_Catalog.Name as serviceName,
  13. SUM(Service_made_AND_Price_Catalog.Price) as sumOf
  14. FROM Service_made_AND_Price_Catalog JOIN Service_made
  15. ON Service_made_AND_Price_Catalog.Id = Service_made.Id
  16. GROUP BY Service_made_AND_Price_Catalog.Name
  17. ORDER BY sumOf
  18.  
  19. --show all endodonists with nr of their workshifts, there is need for job cuts and one with the least workshifts needs to go
  20. SELECT Dentists.License_number as dentists, Specialization.Type_of_specialization as spec,
  21. (SELECT COUNT(*) FROM Work_shift WHERE Work_shift.License_number = Dentists.License_number) as nrOfH
  22. FROM Dentists, Specialization
  23. WHERE Specialization.License_number = Dentists.License_number and Specialization.Type_of_specialization IN( 'Endodontist')
  24.  
  25.  
  26. --show occupied hours of all dental assistants during certain work shift
  27.  
  28. SELECT Dental_assistant_id, Occupied_hours.Start_time, Occupied_hours.Finish_time, Work_shift.Day_of_the_week
  29. FROM Occupied_hours JOIN Work_shift ON Occupied_hours.Work_shift_id = Work_shift.Id
  30. WHERE Day_of_the_week IN('Monday')
  31.  
  32.  
  33. --
  34. --DROP VIEW IF EXISTS CD
  35. --GO
  36. ----CREATE VIEW CD AS
  37. ---- SELECT People.Name, People.Surname, Diseases.Id as diseaseID
  38. ---- FROM People, Diseases
  39. ---- WHERE Diseases.Personal_identity_number = People.Personal_identity_number;
  40.  
  41. ----GO
  42.  
  43. ----SELECT CD.Name, CD.Surname, Diseases_Catalog.Name, Diseases_Catalog.What_it_is
  44. ---- FROM CD, Diseases_Catalog
  45. ---- WHERE Diseases_Catalog.Id = CD.diseaseID
  46.  
  47.  
  48. --show how many times each dentist worked with each assistant
  49.  
  50. SELECT Dentists.Personal_identity_number, Dental_Assistant.Personal_identity_number, COUNT(Work_hours.Id) as nrOfTimes
  51. FROM Work_hours, Dental_Assistant, Dentists
  52. WHERE Work_hours.Dental_assistant_id = Dental_Assistant.Id and Work_hours.License_number = Dentists.License_number
  53. GROUP BY Dentists.Personal_identity_number, Dental_Assistant.Personal_identity_number
  54. ORDER BY nrOfTimes
  55.  
  56.  
  57.  
  58. -- show dentists who arent likely to treat children who actually treated children
  59. DROP VIEW IF EXISTS CV
  60. GO
  61. CREATE VIEW CV AS
  62. SELECT People.Name +' '+ People.Surname as cvName, People.Age as cvAge, Visits.Work_shift_id as cvWK
  63. FROM People, Visits
  64. WHERE People.Personal_identity_number = Visits.Personal_identity_number
  65. GO
  66.  
  67. DROP VIEW IF EXISTS WCV
  68. GO
  69. CREATE VIEW WCV AS
  70. SELECT cvName as customerName, cvAge as customerAge, Work_hours.License_number as dentistLicense
  71. FROM CV, Work_hours
  72. WHERE cvWK = Work_hours.Id
  73. GO
  74.  
  75. SELECT * FROM WCV
  76. WHERE customerAge < 18
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement