Advertisement
KillianMills

SQL Queries

Oct 30th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.00 KB | None | 0 0
  1. /*Question 1*/
  2.  
  3. /*(a)*/
  4. SELECT Name, LifeExpectancy, Continent
  5. FROM Country
  6. WHERE LifeExpectancy < 60;
  7.  
  8. /*(b)*/
  9. SELECT Continent, AVG(LifeExpectancy)
  10. FROM Country
  11. WHERE Continent != 'Antartica'
  12. GROUP BY Continent;
  13.  
  14. /*(c)*/
  15. SELECT c.Name, ci.District, c.LifeExpectancy, c.Continent
  16. FROM Country AS c, City AS ci
  17. WHERE c.LifeExpectancy < 60
  18. AND c.Code = ci.CountryCode
  19. GROUP BY District;
  20.  
  21.  
  22. /*Question 2*/
  23.  
  24. /*(a)*/
  25. INSERT INTO CountryLanguage (CountryCode, LANGUAGE, IsOfficial, Percentage)
  26. VALUES('IRL', 'Hindi', 'F' , 2.6 );
  27.  
  28. /*(b)*/
  29. SELECT c.Name, c.HeadOfState, AVG(ci.Population)
  30. FROM Country AS c, City AS ci
  31. WHERE c.Code = ci.CountryCode
  32. AND c.Continent = 'Europe'
  33. AND (ci.Population > 300000 )
  34. GROUP BY c.Name;
  35.  
  36. /*(c)*/
  37. SELECT c.Name, Capital, AVG(ci.Population), c.SurfaceArea
  38. FROM Country c, City ci, CountryLanguage cl
  39. WHERE c.Continent = 'Oceania'
  40. AND cl.LANGUAGE = 'English'
  41. AND c.Capital = ci.ID
  42. AND c.Code = cl.CountryCode
  43. AND (ci.Population > 10000)
  44. GROUP BY c.Name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement