测试内容:10章--13章
1、返回以下格式的查找结果:
张三(男):24岁
要求生成一个新列,列名为result,该列按上述格式显示出人名只有两个字,email地址长度大于15个字符的所有命中记录的所有列(包含新列,且email地址全部转换为大写);
2、返回四个值,分别是数据表中的总人数,年龄的最大值、最小值和平均值,并分别命名列名为total_num、max_age、min_age和avg_age;
3、返回一个值avg_age,要求统计的是除去一个年纪最大的和年纪最小的之后的其他人年龄的平均值;
4、按性别统计辽宁省的党员数量;
5、统计出不同省份不同性别的党员与非党员数量最多的组的人数;
6、查找出年纪较大的(不是最大的)前5个人,并按性别统计人数。
答案:
1、答:
select id,name,gender,home, upper(email) as email, age, party,concat(name,':(',cast(age as char),')','岁
') as result from student where length(email) > 15
2、答:
select count(id) as total_num, max(age) as max_age, min(age) as min_age,avg(age) as avg_age from student
3、答:
select avg(age) as avg_age from student where age != (
select age from student order by age limit 1
) and age != (
select age from student order by age desc limit 1
)
4、答:
SELECT count(*) FROM `student` where party = 1 and home like '辽宁省%' group by gender
5、答:
select result from(
SELECT count(*) as result FROM student group by home like '辽宁省%',gender
) as foo order by result desc limit 1
6、答:
SELECT count(*) FROM (
select * from student order by age desc limit 1,5
) as tmp group by gender
阅读(2388) | 评论(0) | 转发(1) |