Guest User

Untitled

a guest
Dec 15th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. # SELECT FROM LIMIT
  2.  
  3. All of the information on the stations table.
  4. Max, min, and mean temp from the conditions table.
  5. id, start_station_id, and duration of five trips.
  6.  
  7. SELECT * From stations;
  8. SELECT max_temperature_f, min_temperature_f, mean_temperature_f FROM conditions;
  9. SELECT id, start_station_id, duration FROM trips LIMIT 5;
  10.  
  11. # WHERE
  12.  
  13. Trips that started at the station with an id of 2.
  14. Stations that have a dock_count of 15.
  15. id, date, and precipitation for conditions with more than 1 inch of precipitation.
  16.  
  17.  
  18. SELECT * FROM trips WHERE start_station_id = 2;
  19. SELECT * FROM stations WHERE dock_count = 15;
  20. SELECT id, date, precipitation_inches FROM conditions WHERE precipitation_inches > 1;
  21.  
  22. # max/min/count/average
  23.  
  24. Duration of the longest trip.
  25. Duration of the shortest trip.
  26. Average dock_count at a station.
  27. Highest dock_count at a station.
  28. Count of days with no rain.
  29. Name/dock_count of the station with the most docks.
  30. Id, start station id, and duration of the longest trip.
  31. Id, start station id, and duration of the shortest trips.
  32.  
  33. SELECT MAX(duration), id FROM trips;
  34. SELECT MIN(duration), id FROM trips;
  35. SELECT ROUND(AVG(dock_count), 2) FROM stations;
  36. SELECT MAX(dock_count) FROM stations;
  37. SELECT COUNT(id) FROM conditions WHERE precipitation_inches = 0;
  38. SELECT name, dock_count FROM stations ORDER BY dock_count DESC LIMIT 1;
  39. SELECT id, start_station_id, duration FROM trips ORDER BY duration DESC LIMIT 1;
  40. SELECT id, start_station_id, duration FROM trips ORDER BY duration ASC LIMIT 1;
  41.  
  42.  
  43. # JOIN
  44.  
  45. Name of the station where the longest trip started.
  46. Name of the stations where the shortest trips started.
  47.  
  48. SELECT stations.name FROM stations JOIN trips ON stations.id = trips.start_station_id WHERE trips.duration = (SELECT max(trips.duration) FROM trips);
  49. SELECT stations.name FROM stations JOIN trips ON stations.id = trips.start_station_id WHERE trips.duration = (SELECT min(trips.duration) FROM trips);
  50.  
  51. # GROUP
  52.  
  53. Count of trips started at each station.
  54. Count of trips ended at each station.
  55. Count of trips started on days with more than an inch of precipitation.
  56.  
  57. SELECT COUNT(start_station_name) AS trips, start_station_name FROM trips GROUP BY start_station_name ORDER BY trips DESC;
  58. SELECT COUNT(end_station_name) AS trips, end_station_name FROM trips GROUP BY end_station_name ORDER BY trips DESC;
  59. SELECT COUNT(trips.start_station_id) AS trips, trips.start_date FROM trips JOIN conditions on trips.start_date = conditions.date WHERE precipitation_inches > 1 GROUP BY trips.start_date;
  60.  
  61. # ORDER
  62.  
  63. Top five stations with the most trips started.
  64. Top five stations with the most trips ended.
  65. Least popular start station.
  66. mean_temperature and precipiation on the five dates with the most trips.
Add Comment
Please, Sign In to add comment