Guest User

Untitled

a guest
Oct 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #1 Get all restaurants
  2. SELECT * FROM restaurants;
  3.  
  4. #2 Get Italian restaurants
  5. SELECT * FROM restaurants WHERE cuisine = 'Italian';
  6.  
  7. #3 Get 10 Italian restaurants, subset of fields
  8. SELECT id, name FROM restaurants WHERE cuisine = 'Italian' LIMIT 10;
  9.  
  10. #4 Count of Thai restaurants
  11. SELECT count(*) from restaurants WHERE cuisine = 'Thai';
  12.  
  13. #5 Count of restaurants
  14. SELECT count(*) from restaurants;
  15.  
  16. #6 Count of Thai restaurants in zip code
  17. SELECT count(*) from restaurants WHERE cuisine = 'Thai' AND address_zipcode = '1
  18. 1372';
  19.  
  20. #7 Italian restaurants in one of several zip codes
  21. SELECT id, name FROM restaurants
  22. WHERE cuisine = 'Italian' AND address_zipcode in ('10012', '10013', '10014')
  23. ORDER BY name ASC
  24. LIMIT 5;
  25.  
  26. #8 Create a restaurant
  27. INSERT INTO restaurants (name, borough, cuisine, address_building_number, address_street, address_zipcode)
  28. VALUES ('Byte Cafe', 'Brooklyn', 'coffee', '123', 'Atlantic Avenue', '11231');
  29.  
  30. #9 Create a restaurant and return id and name
  31. INSERT INTO restaurants (name, borough, cuisine, address_building_number, address_street, address_zipcode)
  32. VALUES ('Byte Cafe', 'Brooklyn', 'coffee', '123', 'Atlantic Avenue', '11231')
  33. RETURNING id, name;
  34.  
  35. #10 Create three restaurants and return id and name
  36. INSERT INTO restaurants (name, borough, cuisine, address_building_number, address_street, address_zipcode)
  37. VALUES ('Test 1', 'Brooklyn1', 'coffee1', '123', 'Atlantic Avenue111', '11111'),
  38. ('Test 2', 'Brooklyn2', 'coffee2', '222', 'Atlantic Avenue222', '22222'),
  39. ('Test 3', 'Brooklyn3', 'coffee3', '333', 'Atlantic Avenue333', '33333')
  40. RETURNING id, name;
  41.  
  42. #11 Update a record
  43. UPDATE restaurants SET name = 'DJ Reynolds Pub and Restaurant' WHERE nyc_restaurant_id = '30191841';
  44.  
  45. #12 Delete by id
  46. DELETE FROM grades WHERE id = 10;
  47.  
  48. #13 A blocked delete
  49. DELETE FROM restaurants WHERE id = 22;
  50.  
  51. #14 Create a table
  52. CREATE TABLE inspectors (
  53. id SERIAL PRIMARY KEY,
  54. first_name TEXT NOT NULL,
  55. last_name TEXT NOT NULL,
  56. borough borough_options
  57. );
  58.  
  59. #15 Update a table
  60. ALTER TABLE grades ADD COLUMN notes TEXT;
  61.  
  62. #16 Drop a table
  63. DROP TABLE inspectors;
Add Comment
Please, Sign In to add comment