Advertisement
panaewboi

lab5 part1 complete

Sep 9th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.66 KB | None | 0 0
  1. ----- PRACTICE 1 -----
  2. SELECT * FROM propertyforrent;
  3.  
  4. SELECT COUNT(*) FROM  propertyforrent;
  5. -- 1. How many clients are there?
  6.  
  7. SELECT COUNT(*) FROM propertyforrent WHERE TYPE = 'Flat';
  8. -- 2. How many clients whose preferred property type are Flat?
  9.  
  10. SELECT AVG(rent) FROM propertyforrent WHERE TYPE = 'Flat' AND rooms = 3;
  11. -- 3. What is average rent for three-room flat?
  12.  
  13. SELECT POSITION, COUNT(staffno), MIN(salary), MAX(salary), AVG(salary)
  14.     FROM staff
  15.     GROUP BY POSITION;
  16. -- 4. What are the number of staff and the minimum, maximum and average staff salary in each staff position?
  17.  
  18. SELECT * FROM viewing;
  19.  
  20. SELECT clientno, COUNT(clientno)
  21.     FROM viewing
  22.     GROUP BY clientno HAVING COUNT(clientno)>1;
  23. -- 5. Which clients have viewed the properties more than one time?
  24.  
  25. SELECT * FROM propertyforrent;
  26.  
  27. SELECT ownerno, COUNT(*)
  28.     FROM propertyforrent
  29.     GROUP BY ownerno;
  30. -- 6. How many properties are owned by each property owner?
  31.  
  32. SELECT propertyno, COUNT(staffno),TYPE
  33.     FROM propertyforrent
  34.     GROUP BY propertyno, TYPE;
  35. -- 7. Count the number of properties by staff number and type of property
  36.  
  37. SELECT * FROM registration;
  38.  
  39. SELECT branchno, COUNT(clientno) FROM registration
  40. GROUP BY branchno;
  41. -- 8. How many customers register in each branch? Show the branch number and the number of customers.
  42.  
  43. SELECT * FROM propertyforrent;
  44.  
  45. SELECT TYPE, COUNT(TYPE)
  46. FROM propertyforrent
  47. GROUP BY TYPE;
  48. -- 9. Find out the total number of properties rented by type of property.
  49.  
  50. SELECT city, TYPE, AVG(rent)
  51. FROM propertyforrent
  52. GROUP BY city, TYPE;
  53. -- 10.Find out the average rent of property rented by city and by type of property.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement