Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Queries
  2. 1.
  3. SELECT petID AS ID, petName AS Name, petAge AS Age
  4. FROM Pets
  5. WHERE UPPER(SUBSTR(petName,1,1)) BETWEEN 'A' AND 'M'
  6. ORDER BY petID
  7. 2.
  8. SELECT doctorID AS ID, name, officeNo AS "Office Number", COUNT(appointmentID) AS "Number of Appointments"
  9.  FROM Doctors
  10. JOIN Appointments USING (doctorID)
  11. WHERE shiftPattern IN ('p','P')
  12. GROUP BY doctorID, name, officeNo
  13. HAVING COUNT (appointmentID)>=3;
  14. 3.
  15. SELECT petID AS ID, petName AS Name, COUNT(appointmentID)AS "Number of Appointments"
  16. FROM Pets JOIN Appointments USING (petID)
  17. WHERE apptDate BETWEEN '02-Jan-2019' AND '26-Sep-2019'
  18. GROUP BY petID, petName
  19. HAVING COUNT (appointmentID)>=2;
  20. 4.
  21. SELECT Apt.petID AS ID, Pets.petName AS Name, diag.COST AS "Cost of Appointment"
  22. FROM ((Appointments apt
  23. INNER JOIN Pets ON apt.petID = Pets.petID)
  24. INNER JOIN Diagnosis diag ON apt.AppointmentID = diag.AppointmentID)
  25. WHERE COST < (SELECT AVG(COST) FROM Diagnosis);
  26. (IF we decide TO change how COST works ALL this will run ON a switch CASE FOR age)
  27. 5.
  28. SELECT apt.doctorID AS "Doctor ID", drs.shiftPattern AS "Shift Pattern", COUNT(apt.appointmentID) AS "Number of Appointments", apt.petID AS "Pet ID", Pets.petName AS "Pet Name", apt.apptDate AS "Appointment Date"
  29. FROM (((Appointments apt
  30. INNER JOIN Pets ON apt.petID= Pets.petID)
  31. INNER JOIN Doctors drs ON apt.doctorID = drs.doctorID)
  32. INNER JOIN Diagnosis diag ON apt.AppointmentID = diag.AppointmentID)
  33. WHERE UPPER(diag.diagnosisDesc) LIKE UPPER('%dental%') OR UPPER(diag.diagnosisDesc)  LIKE UPPER('%socialisation%') AND apt.apptDate <'21-Sep-2019'
  34. GROUP BY apt.doctorID, drs.shiftPattern, apt.petID, Pets.petName, apt.apptDate;
  35. 6.
  36. SELECT petID AS "Pets without Appointments"
  37. FROM Pets
  38. MINUS
  39. SELECT DISTINCT petID
  40. FROM Appointments;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement