b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

mysql优化_mysql sql优化_mysql优化面试题(12)

电脑杂谈  发布时间:2017-02-26 12:40:16  来源:网络整理

insert into tea_stu values(3,3), (3,4), (3,1);

insert into tea_stu values(4,4), (4,1), (4,2) , (4,3);

结果:2à3,3à2,4à3

解题思路:(真实面试答题时,也要写出每个分析步骤,如果纸张不够,就找别人要)

1要会统计分组信息,统计信息放在中间表中:

select teaid,count(*) from tea_stu group by teaid;

2接着其实应该是筛除掉小于12岁的学生,然后再进行统计,中间表必须与student关联才能得到12岁以下学生和把该学生记录从中间表中剔除,代码是:

select tea_stu.teaid,count(*) total from student,tea_stu

where student.stuid=tea_stu.stuid and student.age>12 group bytea_stu.teaid

3.接着把上面的结果做成虚表与teacher进行关联,并筛除大于45的老师

select teacher.teaid,teacher.name,total from teacher ,(selecttea_stu.tea

id,count(*) total from student,tea_stu wherestudent.stuid=tea_stu.stuid and stu

dent.age>12 group by tea_stu.teaid) as tea_stu2 whereteacher.teaid=tea_stu2.tea

id and teacher.age<45;

7.求出发帖最多的人:

select authorid,count(*) total from articles

group by authorid

having total=

(select max(total2) from (select count(*) total2 from articlesgroup by authorid) as t);

select t.authorid,max(t.total) from

(select authorid,count(*) total from articles )as t

这条语句不行,因为max只有一列,不能与其他列混淆。

select authorid,count(*) total from articles

group by authorid having total=max(total)也不行。

10、一个用户表中有一个积分字段,假如中有100多万个用户,若要在每年第一天凌晨将积分清零,你将考虑什么,你将想什么办法解决?

解决方案一,update user set score=0;

解决方案二,假设上面的代码要执行好长时间,超出我们的容忍范围,那我就alter table user drop columnscore;alter table user add column score int。

下面代码实现每年的那个凌晨时刻进行清零。

Runnable runnable =

new Runnable(){

public void run(){

clearDb();

schedule(this,new Date(new Date().getYear()+1,0,0));

}

};

schedule(runnable,

new Date(new Date().getYear()+1,0,0));


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34607-12.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...