This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table drivers ( | |
id serial primary key, | |
first_name varchar, | |
last_name varchar | |
); | |
create table vehicles ( | |
id serial primary key, | |
make varchar, | |
model varchar, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE vehicles SET registration_date = CURRENT_DATE - INTERVAL '11 months' WHERE id = 1; | |
UPDATE vehicles SET registration_date = CURRENT_DATE - INTERVAL '12 months' WHERE id = 2; | |
UPDATE vehicles SET registration_date = CURRENT_DATE - INTERVAL '18 months' WHERE id = 3; | |
UPDATE vehicles SET registration_date = CURRENT_DATE - INTERVAL '20 months' WHERE id = 4; | |
SELECT d.first_name, d.last_name, v.make, v.model, v.registration_date | |
FROM drivers d | |
JOIN vehicles v ON d.id = v.driver_id | |
WHERE v.registration_date = CURRENT_DATE - INTERVAL '11 months'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE vehicles | |
ADD registration_date TIMESTAMP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT count(*) | |
FROM vehicles, drivers | |
WHERE drivers.id = vehicles.driver_id and vehicles.make = 'Nissan'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE drivers | |
ADD email VARCHAR(255); | |
ALTER TABLE drivers | |
ADD address VARCHAR(255); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE vehicles SET color = 'red'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE vehicles | |
ADD color VARCHAR(255); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--1 | |
INSERT INTO drivers (id,first_name, last_name) VALUES (1,'Amy', 'Hua'); | |
INSERT INTO drivers (id,first_name, last_name) VALUES (2,'Koshi', 'Kawasaki'); | |
INSERT INTO drivers (id,first_name, last_name) VALUES (3,'Joel', 'Batoo'); | |
INSERT INTO drivers (id,first_name, last_name) VALUES (4,'Madam', 'Zelda'); | |
INSERT INTO vehicles (driver_id,make, model) VALUES (1,'Ford','Escape'); | |
INSERT INTO vehicles (driver_id,make, model) VALUES (2,'Jeep','Wrangler'); | |
INSERT INTO vehicles (driver_id,make, model) VALUES (3,'Toyota','Prius'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POST method route | |
app.post('/', function (req, res) { | |
res.send('POST received'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solution 1 | |
app.get('/data', function(req, res) { | |
res.send('welcome!'); | |
}); | |
// Solution 2 | |
app.get('/data', (req, res) => { | |
res.send('welcome!'); | |
}); |
NewerOlder