SQL island is a fun way to practice SQL queries. The site can be found here: https://sql-island.informatik.uni-kl.de/ My completion certificate can be found attached.
Certificate_SQL-Island Liberty Rodriguez.pdf
Questions and Answers
SELECT *
FROM inhabitant;
SELECT *
FROM inhabitant
WHERE state = 'friendly';
There is no way around getting a sword for myself. I will now try to find a friendly weaponsmith to forge me one.
SELECT *
FROM inhabitant
WHERE state = ‘friendly’
AND job = ‘weaponsmith’;
SELECT *
FROM inhabitant
WHERE state = ‘friendly’
AND job LIKE ‘%smith’;
SELECT personid
FROM INHABITANT
WHERE name = ‘Stranger’;
I can offer to make you a sword for 150 gold. That’s the cheapest you will find! How much gold do you have?
SELECT gold
FROM INHABITANT
WHERE name = ‘Stranger’;
Damn! No mon, no fun. There has to be another option to earn gold other than going to work. Maybe I could collect ownerless items and sell them! Can I make a list of all items that don’t belong to anyone?
SELECT *
FROM ITEM
WHERE owner IS null;
UPDATE item
SET owner = 20
WHERE owner IS NULL;
Now list all of the items I have!
SELECT *
FROM ITEM
WHERE owner = 20
Find a friendly inhabitant who is either a dealer or a merchant. Maybe they want to buy some of my items.
SELECT *
FROM INHABITANT
WHERE state = ‘friendly’
AND job = ‘dealer’
OR job = ‘merchant’
I’d like to get the ring and the teapot. The rest is nothing but scrap. Please give me the two items. My personid is 15.
UPDATE item
SET owner = 15
WHERE item = ‘ring’
OR item = ‘teapot’
Unfortunately, that’s not enough gold to buy a sword. Seems like I do have to work after all. Maybe it’s not a bad idea to change my name from Stranger to my real name before I will apply for a job.
UPDATE inhabitant
SET name = ‘Elrond’
WHERE personid = 20
SELECT *
FROM inhabitant
WHERE job = ‘baker’
ORDER BY gold DESC
SELECT *
FROM inhabitant
WHERE job = ‘pilot’
SELECT inhabitant.name
FROM village, inhabitant
WHERE village.chief = inhabitant.personid
AND village.name = ‘Onionville’
Hello Liberty, the pilot is held captive by Dirty Dieter in his sister’s house. Shall I tell you how many women there are in Onionville? Nah, you can figure it out by yourself!
SELECT COUNT(*)
FROM inhabitant, village
WHERE village.villageid = inhabitant.villageid
AND village.name = ‘Onionville’
AND gender = ‘f’
SELECT name
FROM inhabitant
WHERE villageid = 3
AND gender = ‘f’
Oh no, baking bread alone can’t solve my problems. If I continue working and selling items though, I could earn more gold than the worth of gold inventories of all bakers, dealers and merchants together. How much gold is that?
SELECT SUM(inhabitant.gold)
FROM inhabitant
WHERE job = ‘baker’
OR job = ‘dealer’
OR job = ‘merchant’
Very interesting: For some reason, butchers own the most gold. How much gold do different inhabitants have on average, depending on their state (friendly, …)?
SELECT state, AVG(inhabitant.gold)
FROM inhabitant
GROUP BY state
ORDER BY AVG(inhabitant.gold)
DELETE FROM inhabitant
WHERE name = ‘Dirty Diane’
UPDATE inhabitant
SET state = 'friendly'
WHERE state = ‘kidnapped’