CREATE TABLE People
(
Id int NOT NULL IDENTITY,
FirstName varchar(100) NOT NULL,
LastName varchar(100) NOT NULL
)
-- ** Problem 1:
-- Add a column, FavoriteColor (optional, not required, varchar(100)), to the previous table.
-- Write the statement here:
ALTER table People
ADD FavoriteColor varchar(100)
-- ** Problem 2:
-- Insert the following names into the People table:
-- Eric Dainty
-- Eric Frolicker
-- Eric Dancer
-- Luke Powers
-- Luke Masters
-- Shirley Hoover
-- Max Eagerson
-- Write the statement here:
INSERT INTO People(FirstName,LastName) VALUES
('Eric', 'Dainty'),('Eric', 'Frolicker'),('Eric', 'Dancer'),
('Luke', 'Powers'),('Luke', 'Masters'),('Shirley', 'Hoover'),
('Max', 'Eagerson')
-- ** Problem 3:
-- Update all records in the People table so that FavoriteColor is 'Orange'
-- Write the statement here:
UPDATE People SET FavoriteColor = 'Orange'
-- ** Problem 4:
-- Write a query that finds all records where the last name ends with the letter "n".
-- Write the statement here:
SELECT * FROM People WHERE LastName LIKE '%n'
-- ** Problem 5:
-- Write a query to provide a list of all the FirstName values that are in the table,
-- along with how many times they names are in there:
-- Example results:
-- FirstName Num
-- Eric 3
-- Luke 2
-- Shirley 1
-- Max 1
-- Write the statement here:
SELECT FirstName, count(Id) as Num from People group by FirstName
-- ** Problem 6:
-- Modify the query for problem five to only show FirstName values that are in the table once.
-- Example results:
-- FirstName Num
-- Shirley 1
-- Max 1
-- Write the statement here:
SELECT FirstName, count(Id) as Num from People group by FirstName
having count(Id) = 1