Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1 Get all restaurants
- SELECT * FROM restaurants;
- #2 Get Italian restaurants
- SELECT * FROM restaurants WHERE cuisine = 'Italian';
- #3 Get 10 Italian restaurants, subset of fields
- SELECT id, name FROM restaurants WHERE cuisine = 'Italian' LIMIT 10;
- #4 Count of Thai restaurants
- SELECT count(*) from restaurants WHERE cuisine = 'Thai';
- #5 Count of restaurants
- SELECT count(*) from restaurants;
- #6 Count of Thai restaurants in zip code
- SELECT count(*) from restaurants WHERE cuisine = 'Thai' AND address_zipcode = '1
- 1372';
- #7 Italian restaurants in one of several zip codes
- SELECT id, name FROM restaurants
- WHERE cuisine = 'Italian' AND address_zipcode in ('10012', '10013', '10014')
- ORDER BY name ASC
- LIMIT 5;
- #8 Create a restaurant
- INSERT INTO restaurants (name, borough, cuisine, address_building_number, address_street, address_zipcode)
- VALUES ('Byte Cafe', 'Brooklyn', 'coffee', '123', 'Atlantic Avenue', '11231');
- #9 Create a restaurant and return id and name
- INSERT INTO restaurants (name, borough, cuisine, address_building_number, address_street, address_zipcode)
- VALUES ('Byte Cafe', 'Brooklyn', 'coffee', '123', 'Atlantic Avenue', '11231')
- RETURNING id, name;
- #10 Create three restaurants and return id and name
- INSERT INTO restaurants (name, borough, cuisine, address_building_number, address_street, address_zipcode)
- VALUES ('Test 1', 'Brooklyn1', 'coffee1', '123', 'Atlantic Avenue111', '11111'),
- ('Test 2', 'Brooklyn2', 'coffee2', '222', 'Atlantic Avenue222', '22222'),
- ('Test 3', 'Brooklyn3', 'coffee3', '333', 'Atlantic Avenue333', '33333')
- RETURNING id, name;
- #11 Update a record
- UPDATE restaurants SET name = 'DJ Reynolds Pub and Restaurant' WHERE nyc_restaurant_id = '30191841';
- #12 Delete by id
- DELETE FROM grades WHERE id = 10;
- #13 A blocked delete
- DELETE FROM restaurants WHERE id = 22;
- #14 Create a table
- CREATE TABLE inspectors (
- id SERIAL PRIMARY KEY,
- first_name TEXT NOT NULL,
- last_name TEXT NOT NULL,
- borough borough_options
- );
- #15 Update a table
- ALTER TABLE grades ADD COLUMN notes TEXT;
- #16 Drop a table
- DROP TABLE inspectors;
Add Comment
Please, Sign In to add comment