面试题全集由php高级技术群收集2、mysql_第1页
面试题全集由php高级技术群收集2、mysql_第2页
面试题全集由php高级技术群收集2、mysql_第3页
面试题全集由php高级技术群收集2、mysql_第4页
面试题全集由php高级技术群收集2、mysql_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

2、如何判断SQL语句的运行效率?如何优化一个查询SQL?通过showstatus命令了解各种SQL的执行频率:exinselect*fromtablewhereid=1000;1:SELECT*FROMorderWHEREYEAR(orderDate)<2008;(慢)SELECT*FROMorderWHEREorderDate<"2008-01-01";(快)2:SELECT*FROMorderWHEREaddtime/7<24;(慢)SELECT*FROMorderWHEREaddtime<24*7;(快)3:SELECT*FROMorderWHEREtitlelikeSELECT*FROMorderWHEREtitle>="good"and3、设定的用户数量在千万级,但是活跃用户的数量只有1%,如何通过优化数据库提高活跃用户的速度?4、服务器在运行的过程中,随着用户数量的增长,如何通过优化,保证性5、请写出5个常用的SQL操作关键字.5分Select、update/insert/delete/create/6、请列出5个常用的PHP操作MySQL5分int(10)char(16)varchar(16)datetimetext8、有两张数据表,表user(id,name)记录了用户的ID和昵称,表article(id,uid,title,content,time)记录了用户的文章标题.内容和时间,写一个SQL语句打印出每个用户的昵称及其的文章总数。5分S,count(a.id)fromuseru,articleawhereu.id=,count(a.id)fromuseruleftjoinarticleaonu.id=a.uidgroupbyu.id值是多少?(5分)MyISAM:20InnoDB:17 receintoA(id,c1,c2)selectid,c1,c2fromBwhereage>50;updateAa,Bbseta.c1=b.c1,a.c2=b.c2wherea.id=b.idandb.age>50;索引和非索大,大量,大数据量。表的划分。关联采用第三范式,集群,主从,(一)创建发布系统,表名为message有如下字段(3分)id文章idtitlecontentcategory_idhits(二)同样上述发布系统:表comment记录用户回复内容,字段如下(4分)comment_id回复ididid,关联message表中的idcomment_content回复内容文章idselectm.id,m.title,m.hits,count( ment_id)numfrommessagemleftjoincommentconm.id=c.idgroubym.idorderby ent_id)(三)上述内容管理系统,表category(3分)category_idint(4)notnullauto_increment;categroy_namevarchar(40)not$sql=“selectcategory_id,category_namefrom$result=echo“<selectname=’category_id’>”;While($row=mysql_fetch_assoc($result)){echo“<option}echoCategory类别表Category类别表 Pid上一级类别IDName类别名称Products产品表Product_hit产品点击表IdProduct_idNameHit_timeCategoryid产品类别Hit_ip点击的Input_dateS,,p.input_datefromcategoryc,productspwhereSelectp.id,,count(duct_id)fromproductsp,product_hitwhere group orderbycount(duct_id)desclimitSelectp.id,,count(duct_id)numfromproductsp,product_hithwherep.id=duct_id groupby orderbynumdesclimit10showstatusex写出统计1989-1-1后出生的数量的SQL语Selectcount(*)fromstuwherebirth>’1989-1-1’andsql用户用户编号用户号,用户通讯地址,用户,编号,名称,种类,用户订阅的编号 B、有一个新用户(号=139000000000,通讯地址=A,=P,用户=N),要订阅某本(编号=100001).请写出需要执行的SQL语句:>select*from11213243>select*from123 Selectp.id,,count(c.id)fromcityc,vince_id=p.idgroupbyp.id30、关系S(s#,sname, ),C(c#,cname),SC(s#,c#).其中S#为学生号,sname为学生, 为,c#为课程号,cname为课程名。SelectS.s#,S.sname,S. fromS,SCWhereS.s#=SC.s#andS. =”女”andSC.c#in(selectc#fromCwherecname=”计算机”)selectS.snamefromS,C,SCwhereS.s#=SC.s#andC.c#=SC.c# ame=’计算机’andS. select*fromSwhereS.s#notin(Select S.s#fromS,SCWhereS.s#=SC.s#andSC.c#in(Selectc#fromCwherecname=”数学”))用户分配所有权限从ip来mysdb数据库(root用户为空mysql>createdatabaseifnotexistsmysql>grantallprivilegesonmydb.*toroot@identifiedbymysql>flushprivileges;//刷新系统权限表表2(MyISAM(InnoDB35、请对于据select*fromtableExamplewhere((aandb)andcor(((aandb)and(candd)))优化的语句。select*fromtableExamplewhereaandbandselect*fromloginwherenamelike“%admin%”limit10;40、在数据库test中的一个表student,字段是name,class,score。分别代表、selectclass,count(if(score>=60,score,null)),count(if(score<60,score,null))fromstudentgroupbyclassselectsum(score<60)fromstudentgroupbyIntaltertableuseradd tinyintnotnulldefault1;B、查询出介于20岁到30岁之间的用户select*fromuserwhereagebetween20andC、如果是一个Web频繁的查询,上题的查询如何优化?(为age字段添加索引)altertableuseraddindexindex_age(age);friend请使用php连接mysql,选择出friend表里age20的所有记录打印结果,并统计出userid(int),namescoreuidint),subject(varchar),score(int)selectlast_insert_id();select*fromscorewhereuid=2orderbyscoredesclimit5(3)使用联合查询获取name为“”的用户的总分数selectsum(s.score)fromuseru,scoreswhereu.id==”清空score表deletefrom删除userdroptableMysqlinsertID1815? 74MYSQL(命令行、工具)75memcache(分布式,84一个article表含有titlecladaine以及其他字段请写sql语句, 的8篇文章。select*fromarticleorderbydainedesclimit85、一个article表字段为id/title/type_id/author/content/daine/active,article_type表字段为id/title。要求显示article表的5条文章作者和文章分类名 a.type_id=t.idorderbydainedesclimit586、从表a中删除id大于5同 为1的记录deletefromawhereid>5 87b表和cbcsql语句并insertintocselect*fromselect*frommembersorderbypostsdesclimit两张表pany和Job,分别表示公司和职位表中含有字段NameIDJob表中含有字段:Id,City,CreateDateID,公司IdSQL日期倒序。orderby.idasc,Job.createDatedescmysql>grantallprivilegesonTEST_DB.*totestuser@00identifiedby'106、写出选择出销售额最高的十个产品的SQL语句,利用下表:(product_id,product_name,price,sell_num);其中product_idi(主键,price,sell_numselect*fromproductsorderbyprice*sell_numdesclimit10;108、MYSQL TABLEidintunsignedAUTO_INCREMENT,user_idintunsignedcomment‘id’,tysmallintunsignedcomment‘本次产品数量’,pay_timetimestampcomment‘时间’,PRIMARY)用户每成功付款一笔订单(从进入到离开),会增加一条记录,记录用户的ID(user_id),以及的产品数量。比如:1、208,2//208这个用户2个产select*frompaymentwhereuser_id=100orderbypay_timedesclimitselect*frompaymentwhereuser_id=100orderby

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论