Advertisement
panaewboi

lab3+lab4

Sep 2nd, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 4.16 KB | None | 0 0
  1. --LAB3--
  2.  
  3. SELECT * FROM propertyforrent; --l. List full details of all properties.
  4.  
  5. SELECT * FROM propertyforrent WHERE TYPE='House'; --2. List full details of all properties that are only house type.
  6.  
  7. SELECT * FROM client;
  8. SELECT clientno AS "client number",
  9.         fname AS "first name",
  10.         lname AS "last name",
  11.         telno AS "telephone number"
  12.     FROM client WHERE preftype='Flat'; --3. List the client number, first name, last name and telephone number of all clients whose preferred property type are Flat.
  13.    
  14. SELECT * FROM viewing;
  15. SELECT clientno, viewdate FROM viewing WHERE propertyno = 'PG21' AND comments IS NOT NULL; --4. List the client number and view date of all viewings on property PG21 where the comments are provided.
  16.  
  17. SELECT DISTINCT TYPE FROM propertyforrent; --5. List all type of properties that are for rent.  The result should eliminate the duplicate records. //distinct=different
  18.  
  19. SELECT * FROM staff;
  20. SELECT staffno AS "staff number",
  21.         fname AS "first name",
  22.         lname AS "last name",
  23.         salary AS "salary"
  24.         FROM staff WHERE sex='M'AND salary>10000 ; --6. List the staff number, first name, last name and salary of all staffs who are males with salary greater than 10,000.
  25.        
  26. SELECT * FROM staff;
  27. SELECT staffno AS "staff number",
  28.         fname AS "first name",
  29.         lname AS "last name",
  30.         dob AS "birth date"
  31.         FROM staff WHERE dob>'1-JAN-1960' ORDER BY dob; --7. List the staff number, first name, last name and birth date of all staffs who were born after January 1, 1960. Arrange the result in ascending order by birth date.
  32.        
  33. SELECT * FROM privateowner;
  34. SELECT ownerno AS "owner number",
  35.         fname||lname AS "name",
  36.         address AS "address"
  37.         FROM privateowner WHERE address NOT LIKE '%Glasgow%'; --8. List the owner number, name (first name concatenated with last name), and address of all private owners who do not live in the Glasgow city.
  38.        
  39. SELECT * FROM branch;
  40. SELECT street,city,postcode
  41.         FROM branch WHERE city IN ('Aberdeen','Bristol'); --9. List the address of all branch offices in Aberdeen or Bristol.
  42.        
  43.         SELECT * FROM staff;
  44. SELECT branchno AS "branch no",
  45.         salary AS "salary"
  46.         FROM staff ORDER BY branchno, salary DESC; --10. List the branch no and salary of all staffs. The result should be arranged by branch no, in ascending order, and within branch no, in descending order of salary.
  47.  
  48. --LAB4--
  49. SELECT * FROM branch;
  50. SELECT branchno AS "branch number"
  51.         FROM branch
  52.         WHERE  city IN ('Aberdeen')
  53.         OR street LIKE '%Main Street%'; --1. Show the branch number of all branches that locate in Aberdeen city or on Main street.
  54.        
  55. SELECT * FROM branch WHERE city <> 'London'; --2. List the branches that are not in London // != or <> or not like
  56.  
  57. SELECT * FROM client WHERE preftype = 'Flat' AND maxrent <=400;
  58. --3. Show clients, whose preferred property type are Flat, can rent the property maximum 400.
  59.  
  60. SELECT * FROM client;
  61. SELECT * FROM client WHERE telno LIKE '%77'; --4. Show clients with phone number ending in 77.
  62.  
  63. SELECT * FROM propertyforrent;
  64. SELECT propertyno AS "property number", rent AS "rent cost" FROM propertyforrent WHERE TYPE = 'Flat' AND city = 'Glasgow' AND rooms BETWEEN 3 AND 4; --in (3,4);
  65. --5. Show property number and the rent cost of the flat properties in Glasgow city with at least 3 and up to 4 rooms.
  66.  
  67. SELECT propertyno FROM propertyforrent WHERE ownerno LIKE 'CO87' OR ownerno LIKE 'CO40';
  68. --6. Display the property number of properties with owner number is CO87 or owner number is CO40.
  69.  
  70. SELECT * FROM propertyforrent WHERE staffno IS  NULL;
  71. --7. Show properties that do not have staff number provide. --is null
  72.  
  73. SELECT * FROM staff WHERE POSITION = 'Manager' ORDER BY salary DESC;
  74. --8. Show the staffs with the position Manager and sort the staffs’ information in descending order of salary.
  75.  
  76. SELECT * FROM staff;
  77. SELECT staffno,POSITION,dob FROM staff WHERE dob LIKE ('%JUN%') ORDER BY dob DESC;
  78. --9. Show staff number, position and day of birth of staffs who have birthdate in June. The result should be arranged by birthdate in descending order.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement