Skip to content

Instantly share code, notes, and snippets.

@atomjar
Created January 18, 2017 21:15
Show Gist options
  • Save atomjar/e447f8a9a713d9427503e22e0f83e72f to your computer and use it in GitHub Desktop.
Save atomjar/e447f8a9a713d9427503e22e0f83e72f to your computer and use it in GitHub Desktop.
SQL Assignment
1) SELECT COUNT(*) FROM users;
50
2) SELECT * FROM items ORDER BY price DESC LIMIT 5;
25|Small Cotton Gloves|Automotive, Shoes & Beauty|Multi-layered modular service-desk|9984
83|Small Wooden Computer|Health|Re-engineered fault-tolerant adapter|9859
100|Awesome Granite Pants|Toys & Books|Upgradable 24/7 access|9790
40|Sleek Wooden Hat|Music & Baby|Quality-focused heuristic info-mediaries|9390
60|Ergonomic Steel Car|Books & Outdoors|Enterprise-wide secondary firmware|9341
3) SELECT * FROM items WHERE category = 'Books' ORDER BY price LIMIT 1;
76|Ergonomic Granite Chair|Books|De-engineered bi-directional portal|1496
SELECT * FROM items WHERE category LIKE '%Books%' ORDER BY price LIMIT 1;
76|Ergonomic Granite Chair|Books|De-engineered bi-directional portal|1496
4) SELECT * FROM addresses WHERE street = '6439 Zetta Hills';
43|40|6439 Zetta Hills|Willmouth|WY|15029
user_id = 40
SELECT * FROM users WHERE id = '40';
40|Corrine|Little|[email protected]
Corrine Little lives there.
SELECT * FROM addresses WHERE user_id = '40';
43|40|6439 Zetta Hills|Willmouth|WY|15029
44|40|54369 Wolff Forges|Lake Bryon|CA|31587
5) SELECT * FROM users WHERE first_name = 'Virginie';
39|Virginie|Mitchell|[email protected]
SELECT * FROM addresses WHERE user_id = '39';
41|39|12263 Jake Crossing|New York|NY|10108
42|39|83221 Mafalda Canyon|Bahringerland|WY|24028
UPDATE addresses SET zip = '12345' WHERE id = '41';
SELECT * FROM addresses WHERE user_id = '39';
41|39|12263 Jake Crossing|New York|NY|12345
42|39|83221 Mafalda Canyon|Bahringerland|WY|24028
6) SELECT SUM(quantity) FROM orders;
2125
7) INSERT INTO users (id, first_name, last_name, email) VALUES ('123456', 'Brian', 'Gates', '[email protected]');
INSERT INTO orders (id, user_id, item_id, quantity, created_at) VALUES ('654321', '123456', '40', '11', '5:34');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment