Guest User

Untitled

a guest
Jul 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.08 KB | None | 0 0
  1. a)  How many towers has the mobile phone company got?
  2.  
  3. SELECT COUNT(DISTINCT towerid)
  4. FROM CONNECT
  5.  
  6. b)  What IS the most expensive connection fee OF ALL the plans?
  7.  
  8. SELECT MAX(connectfee)
  9. FROM plan
  10.  
  11. c)  How many mobile phones OF each brand name have been sold TO customers OF the mobile phone company?
  12.  
  13. SELECT brandname,COUNT(*)
  14. FROM mobile
  15. GROUP BY brandname
  16.  
  17. d)  SHOW a list OF the tower usage.  Display the tower ID AND the NUMBER OF calls connected through each tower. (Hint: GROUP BY query USING the CONNECT TABLE)
  18.  
  19. SELECT towerid, COUNT(callsid) AS Number_of_Calls_connected
  20. FROM CONNECT
  21. GROUP BY towerid
  22.  
  23. e)  SHOW the total NUMBER OF female AND male customers the company has.
  24.  
  25. SELECT sex AS Gender, COUNT( * )
  26. FROM customer
  27. GROUP BY sex
  28.  
  29. f)  List the NUMBER OF mobile phones per mobile phone colour.  ONLY SHOW the colours which have more than 25 phones.
  30.  
  31. SELECT phonecolour, COUNT( * )
  32. FROM mobile
  33. GROUP BY phonecolour
  34. HAVING COUNT( mobileid ) >25
  35.  
  36. g)  SHOW the COUNT OF customers FOR each suburb, WITH the highest numbered suburb (COUNT) FIRST AND lowest COUNT LAST ON the list.
  37.  
  38. SELECT Suburb, COUNT( * )
  39. FROM customer
  40. GROUP BY Suburb
  41. ORDER BY COUNT( * ) DESC
  42.  
  43. h)  SHOW the oldest AND youngest DATE OF birth OF ALL customers.
  44.  
  45. SELECT MAX( dob ) AS Youngest, MIN( dob ) AS Oldest
  46. FROM customer
  47.  
  48. i)  What IS the average age OF ALL customers ?
  49.  
  50. SELECT TRUNCATE(avg(datediff(sysdate(),dob)/365.25),0) AS AverageAge
  51. FROM customer
  52.  
  53. j)  What IS the total annual salary being paid OUT TO CURRENT active staff?
  54.  
  55. SELECT SUM( rateperhour *40 *52 ) AS AnnualSalary
  56. FROM staff
  57. WHERE resigned IS NULL
  58.  
  59. k)  SHOW a list OF brand names AND a COUNT OF the UNIQUE customers FOR each brand.
  60.  
  61. SELECT brandname, COUNT( DISTINCT customerid )
  62. FROM mobile
  63. GROUP BY brandname
  64.  
  65. *** (IN process)
  66. l)  FOR calls made IN 2006, display how many calls were made ON each DAY OF the week.
  67. Hint: You can USE the functions dayofweek(), dayname() AND YEAR()
  68.  
  69. SELECT DISTINCT dayname(calldate), COUNT(*)
  70. FROM calls
  71. WHERE YEAR(calldate)=2006
  72. GROUP BY dayname(calldate)
  73. ORDER BY dayofweek(calldate)
Add Comment
Please, Sign In to add comment