1) SELECT DevelopmentID, Name, NumberOfUnits 5) SELECT UnitNumber FROM hdb.Development FROM hdb.Unit WHERE NumberOfUnits>5; WHERE Bedrooms=2 OR Bedrooms=3; (The following also works:) (The following also works:) SELECT * SELECT UnitNumber FROM hdb.Development FROM hdb.Unit WHERE NumberOfUnits>5; WHERE Bedrooms>=2 AND Bedrooms<=3; 2) SELECT HouseholdID 6) SELECT UnitNumber, SquareFootage FROM hdb.Resident FROM hdb.Unit WHERE FirstName=’Brad’ ORDER BY SquareFootage ASC AND LastName=’Pitt’; LIMIT 1; (NOTE: ASC is optional) 3) SELECT COUNT(*) 7) SELECT DevelopmentID, SUM(Bedrooms) FROM hdb.Development; FROM hdb.Unit GROUP BY DevelopmentID; (NOTE: COUNT(DevelopmentID) is also fine) 4) SELECT COUNT(*) 8) SELECT DevelopmentID, SUM(Bedrooms) FROM hdb.Unit FROM hdb.Unit WHERE SquareFootage<2000; GROUP BY DevelopmentID ORDER BY SUM(Bedrooms) DESC (NOTE: do not write 2000 as 2,000) LIMIT 1;
1) SELECT DevelopmentID, Name, NumberOfUnits FROM hdb.Development WHERE NumberOfUnits>5; (The following also works:) SELECT * FROM hdb.Development WHERE NumberOfUnits>5; 5) SELECT UnitNumber FROM hdb.Unit WHERE Bedrooms=2 OR Bedrooms=3; (The following also works:) SELECT UnitNumber FROM hdb.Unit WHERE Bedrooms>=2 AND Bedrooms<=3; 2) SELECT HouseholdID FROM hdb.Resident WHERE FirstName=’Brad’ AND LastName=’Pitt’; 6) SELECT UnitNumber, SquareFootage FROM hdb.Unit ORDER BY SquareFootage ASC LIMIT 1; (NOTE: ASC is optional) 3) SELECT COUNT(*) FROM hdb.Development; (NOTE: COUNT(DevelopmentID) is also fine) 7) SELECT DevelopmentID, SUM(Bedrooms) FROM hdb.Unit GROUP BY DevelopmentID; 4) SELECT COUNT(*) FROM hdb.Unit WHERE SquareFootage<2000; (NOTE: do not write 2000 as 2,000) 8) SELECT DevelopmentID, SUM(Bedrooms) FROM hdb.Unit GROUP BY DevelopmentID ORDER BY SUM(Bedrooms) DESC LIMIT 1;
Additional-SQL-Query-Practice-Problems-Basics.docx