Advertisement
Saita

Untitled

Nov 16th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.45 KB | None | 0 0
  1. /**********QUERIES**********/
  2. #1. Select all records from each table - Label Q1a-Q1i
  3. select * from Agents;
  4. select * from Bikes;
  5. select * from Events;
  6. select * from Participation;
  7. select * from Races;
  8. select * from Rider_Sponsorship;
  9. select * from Riders;
  10. select * from Sponsors;
  11. select * from Teams;
  12.  
  13. #2. List all of your constraints in the database one table at a time. - Label Q2a-Q2i
  14. select * from information_schema.table_constraints
  15. where table_name = 'Agents';
  16. select * from information_schema.table_constraints
  17. where table_name = 'Bikes';
  18. select * from information_schema.table_constraints
  19. where table_name = 'Events';
  20. select * from information_schema.table_constraints
  21. where table_name = 'Participation';
  22. select * from information_schema.table_constraints
  23. where table_name = 'Races';
  24. select * from information_schema.table_constraints
  25. where table_name = 'Rider_Sponsorship';
  26. select * from information_schema.table_constraints
  27. where table_name = 'Riders';
  28. select * from information_schema.table_constraints
  29. where table_name = 'Sponsors';
  30. select * from information_schema.table_constraints
  31. where table_name = 'Teams';
  32.  
  33. #3. List all of your table names in the database. - Label Q3
  34. show tables from EMBRL;
  35.  
  36. #4. List the Columns and data types of each table - Label Q4a-Q4i
  37. describe Agents;
  38. describe Bikes;
  39. describe Events;
  40. describe Participation;
  41. describe Races;
  42. describe Rider_Sponsorship;
  43. describe Riders;
  44. describe Sponsors;
  45. describe Teams;
  46.  
  47. #5. RIDER - POINT TOTALS BY RACE LEVEL LISTING List the Rider's Name, RaceLevel as
  48. #   Race_Level and the total number of all points based on their placement. Make sure that you don't
  49. #   list any riders who have not raced in any races yet (not placed yet). Sort the data from highest to
  50. #   lowest total points. I need a listing for the easy races, one for the intermediate races and one for
  51. #   the advanced races. - Label as Q5a-Q5c.
  52. select Riders.FirstName, Riders.LastName, Races.RaceLevel as Race_Level, sum(Participation.Placement) as Points
  53. from Riders, Races, Participation
  54. where Riders.RiderID = Participation.RiderID
  55.     and Races.RaceID = Participation.RaceID
  56.     and Races.RaceLevel = 'Easy'
  57.     and Participation.Placement is not null
  58. group by Riders.RiderID
  59. order by Points desc;
  60.  
  61. select Riders.FirstName, Riders.LastName, Races.RaceLevel as Race_Level, sum(Participation.Placement) as Points
  62. from Riders, Races, Participation
  63. where Riders.RiderID = Participation.RiderID
  64.     and Races.RaceID = Participation.RaceID
  65.     and Races.RaceLevel = 'Intermediate'
  66.     and Participation.Placement is not null
  67. group by Riders.RiderID
  68. order by Points desc;
  69.  
  70. select Riders.FirstName, Riders.LastName, Races.RaceLevel as Race_Level, sum(Participation.Placement) as Points
  71. from Riders, Races, Participation
  72. where Riders.RiderID = Participation.RiderID
  73.     and Races.RaceID = Participation.RaceID
  74.     and Races.RaceLevel = 'Advanced'
  75.     and Participation.Placement is not null
  76. group by Riders.RiderID
  77. order by Points desc;
  78.  
  79. #6. SEARCHING FOR A RUN
  80. #   List the EventName and the RaceName of any records that have the word "Run" in the Race
  81. #   Name. – Label as Q6
  82. select Events.EventName, Races.RaceName
  83. from Events, Races
  84. where Races.RaceName like '%run%'
  85.     and Events.EventID = Races.EventID;
  86.  
  87. #7. RIDER - TEAM - AGENT BY RACE DATE LISTING
  88. #   List the Rider's Full Name AS "Rider_Name", The Rider's Team Name and their Agent's Full
  89. #   Name listed AS "Agent_Name" .Of those riders only list those who have or are schedule to
  90. #   participate in any races during April 2008 and, make sure that the riders information is only listed
  91. #   once. - Label as Q7
  92. select concat_ws(' ',Riders.FirstName, Riders.LastName) as Rider_Name, Teams.TeamName,
  93.         concat_ws(' ', Agents.FirstName, Agents.LastName) as Agent_Name
  94. from Riders, Teams, Agents, Participation, Races
  95. where Riders.TeamID = Teams.TeamID
  96.     and Riders.AgentID = Agents.AgentID
  97.     and Riders.RiderID = Participation.RiderID
  98.     and Races.RaceID = Participation.RaceID
  99.     and month(Races.RaceDate) = 4
  100.     and year(Races.RaceDate) = 2008
  101. group by Riders.RiderID;
  102.  
  103. #8. SUBQUERY
  104. #   List the Sponsor Name of any sponsors who sponsored both Riders and Events. – Label as Q8
  105. select Sponsors.SponsorName
  106. from Sponsors, Rider_Sponsorship
  107. where Sponsors.SponsorID = Rider_Sponsorship.SponsorID
  108. and Sponsors.SponsorName in (select Sponsors.SponsorName
  109.                              from Sponsors, Events
  110.                              where Sponsors.SponsorID = Events.SponsorID)
  111. group by Sponsors.SponsorID;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement