
DAY4 练习
SUM and COUNT:https://sqlzoo.net/wiki/SUM_and_COUNT/zh
The nobel table can be used to practice more SUM and COUNT functions./zh:https://sqlzoo.net/wiki/The_nobel_table_can_be_used_to_practice_more_SUM_and_COUNT_functions./zh
SUM and COUNT Quiz:https://sqlzoo.net/wiki/SUM_and_COUNT_Quiz
Using Null:https://sqlzoo.net/wiki/Using_Null/zh
Scottish Parliament/zh:https://sqlzoo.net/wiki/Scottish_Parliament/zh
Using Null Quiz:https://sqlzoo.net/wiki/Using_Null_Quiz
--SUM and COUNT/zh--1select sum(population)from world;--2select distinct continentfrom world;--3select sum(GDP)from worldwhere continent = 'Africa';--4select count(name)from worldwhere area >= 1000000;--5select sum(population)from worldwhere name in ('France','Germany','Spain');--6selectcontinent,count(name)from worldgroup by continent;--7selectcontinent,count(name)from worldwhere population >= 10000000group by continent;--8select continentfrom worldgroup by continenthaving sum(population) >= 100000000;--The nobel table can be used to practice more SUM and COUNT functions./zh--1select count(winner)from nobel;--2select distinct subjectfrom nobel;--3select count(subject)from nobelwhere subject = 'physics';--4selectsubject,count(winner)from nobelgroup by subject;--5selectsubject,min(yr)from nobelgroup by subject;--6selectsubject,count(winner)from nobelwhere yr = 2000group by subject;--7selectsubject, count(distinct winner)from nobelgroup by subject;--8selectsubject,count(distinct yr)from nobelgroup by subject;--9select yrfrom nobelwhere subject = 'physics'group by yrhaving count(winner) = 3;--10select winnerfrom nobelgroup by winnerhaving count(winner) > 1;--11select winnerfrom nobelgroup by winnerhaving count(distinct subject) > 1;--12selectyr,subjectfrom nobelwhere yr >= 2000group by yr, subjecthaving count(winner) = 3;--Using Null/zh--1select namefrom teacherwhere dept is null;--2selectteacher.name,dept.namefrom teacher inner join depton teacher.dept = dept.id;--3selectteacher.name,dept.namefrom teacher left join depton teacher.dept = dept.id;--4selectteacher.name,dept.namefrom teacher right join depton teacher.dept = dept.id;--5selectname,coalesce(mobile,'07986 444 2266')from teacher;--6selectteacher.name,coalesce(dept.name,'None')from teacher left join dept on teacher.dept = dept.id;--7selectcount(id),count(mobile)from teacher;--8selectdept.name,count(teacher.id)from teacher right join depton teacher.dept = dept.idgroup by dept.name;--9select name,case when dept in (1,2) then 'Sci'else 'Art' endfrom teacher;--10select name,case when dept in (1,2) then 'Sci'when dept = 3 then 'Art'else 'None' endfrom teacher;--Scottish Parliament/zh/*此章练习没有找到英文的中文翻译不准确,多注意报错内容吧*/--1select namefrom mspwhere Party is null;--2selectName,Leaderfrom partygroup by Name,Leader;--3selectName,Leaderfrom partywhere Leader is not null;--4select party.namefrom msp join party on msp.Party = party.Codegroup by party.Namehaving count(party.name) >= 1;--5selectmsp.Name,party.Namefrom msp left join party on msp.Party = party.Codeorder by msp.Name;--6selectparty.Name,count(msp.Party)from party join msp on party.Code = msp.Partygroup by party.Name,msp.Party;/*认真看报错内容才知道题目细节*/--7selectparty.Name,count(msp.Name)from party left join msp on msp.Party = party.Codegroup by party.name;
注:sql中各种join的区分

*上方图片来自网络
end
文章转载自EGG IXD,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




