欢迎来到天天文库
浏览记录
ID:15443608
大小:74.50 KB
页数:11页
时间:2018-08-03
《常用sql查询语句考试答案及解释》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、%代表任意多个字符_代表一个字符如果我就真的要查%或者_,怎么办呢?使用escape,转义字符后面的%或_就不作为通配符了,注意前面没有转义字符的%和_仍然起通配符作用selectusernamefromgg_userwhereusernamelike'%xiao_%'escape'';selectusernamefromgg_userwhereusernamelike'%xiao%%'escape'';AasB,就是给A起个别名叫Bselecta.*fromtable_1asa就是给table
2、_1起个别名叫a,因此前面就可以使用a.*了比如nameas姓名这样的话,查询出来的列就是写姓名一、单表查询练习1、查询<学生信息表>,查询学生"张三"的全部基本信息Select*fromA_studentinfowheresname='张三'2、查询<学生信息表>,查询学生"张三"和”李四”的基本信息Select*fromA_studentinfowheresname='张三'orsname='李四'3、查询<学生信息表>,查询姓"张"学生的基本信息Select*fromA_studentin
3、fowheresnamelike'张%'4、查询<学生信息表>,查询姓名中含有"四"字的学生的基本信息Select*fromA_studentinfowheresnamelike'%四%'5、查询<学生信息表>,查询姓名长度为三个字,姓“李”,且最后一个字是“强”的全部学生信息。select*fromA_studentinfowheresnamelike'李_强'6、查询<学生信息表>,查询姓"张"或者姓”李”的学生的基本信息。Select*fromA_studentinfowheresname
4、like'张%'orsnamelike'李%'7、查询<学生信息表>,查询姓"张"并且"所属省份"是"北京"的学生信息Select*fromA_studentinfowheresnamelike'张%'andprovince='北京'8、查询<学生信息表>,查询"所属省份"是"北京"、”新疆”、”山东”或者"上海"的学生的信息Select*fromA_studentinfowhereprovincein('北京','上海','新疆','山东')9、查询<学生信息表>,查询姓"张",但是"所属省份
5、"不是"北京"的学生信息Select*fromA_studentinfowheresnamelike'张%'andprovince!='北京'10、查询<学生信息表>,查询全部学生信息,并按照“性别”排序,性别相同的情况下按照“所属省份”排序,所属省份相同的情况下再按照“班级”排序select*fromA_studentinfoorderbysex,province,class11、查询<学生信息表>,查询现有学生都来自于哪些不同的省份selectdistinctprovinceas省份from
6、A_studentinfo12、查询<学生选修信息表>,查询没有填写成绩的学生的学号、课程号和成绩Select*fromA_studentcoursewherescoreisnull13、查询<学生选修信息表>,查询全部填写了成绩的学生的选修信息,并按照“成绩”从高到低进行排序Select*fromA_studentcoursewherescoreisnotnullorderbyscoredesc二、聚合函数练习1、统计<学生信息表>,统计共有多少个学生Selectcount(*)as学生数量f
7、romA_studentinfo2、统计<学生信息表>,统计年龄大于20岁的学生有多少个Selectcount(*)as学生数量fromA_studentinfowhere(2008-yearofbirth)>203、统计<学生信息表>,统计入学时间在1980年至1982年的学生人数selectcount(*)as学生数量fromA_studentinfowhereenrollmentbetween'1998-01-01'and'2003-12-30'对比以下查询方式,看看有何不同,为什么?se
8、lectcount(*)as学生数量fromA_studentinfowhereenrollmentbetween'1998'and'2003'4、统计<学生选修信息表>,统计学号为"S001"的学生的平均成绩Selectavg(score)as平均成绩fromA_studentcoursewheresno='S001'5、统计<学生选修信息表>,统计学号为"S001"的学生的总成绩selectsum(score)as总成绩fromA_studentcoursewheresno='S001'6、
此文档下载收益归作者所有