宁波有没有开发网站的公司,深圳关键词优化报价,根据描述生成图片的网站,网站建设公司 跨界鱼科技专业一、简单查询1.最简单查询(查所有数据)select * from 表名 注意#xff1a;* 代表所有列#xff0c;并不是代表所有行例#xff1a;select * from test2.查询指定列select 列名,列名 from 表名例#xff1a;select code,name from test3.修改结果集的列名 asselect 列名 …一、简单查询1.最简单查询(查所有数据)select * from 表名 注意* 代表所有列并不是代表所有行例select * from test2.查询指定列select 列名,列名 from 表名例select code,name from test3.修改结果集的列名 asselect 列名 as 显示的字 from 表名例select code as 代号,name as 姓名 from test4.条件查询select * from 表名 where 条件例select * from test where coden0035.多条件查询或者 orselect * from 表名 where 条件 or 条件例select * from test where codep003 or nationn001并且 andselect * from 表名 where 条件 and 条件例select * from test where codep004 and nationn0016.范围查询 (某一列的内容是谁到谁之间的数据)例两种写法查找汽车价格在40到60之间(1)select * from car where price40 and price60(2)select * from car where price between 40 and 607.离散查询查询汽车价格在(10、20、30、40、50、60)中出现的信息 in例两种写法(1)select * from car where price10 or price20 or price30 or price40 or price50 or price60(2)select * from car where price in(10,20,30,40,50,60)不在(10、20、30、40、50、60)中出现的信息 not in例select * from car where price not in(10,20,30,40,50,60)8.模糊查询(关键字查询)like%:任意n个字符_:任意一个字符查询汽车表名称中包含奥迪例select * from car where namelike %奥迪%查询汽车表名称第二个字符为“马”的汽车例select * from car where name like _马%9.排序查询 order by升序 asc可省略例汽车表中价格列升序select * from car order by price asc降序 desc(从高到低)例汽车表中油耗列降序select * from car order by oil desc先a列升序后b列降序例汽车表中先将a列升序后将b列降序select * from car order by a,b desc10.去重查询 distinct例查找汽车表中型号一样的去重select distinct brand from car11.分页查询一页显示m条数据 当前是第n页limit (n-1)*m,m一页显示10条数据 当前是第二页 跳过多少条取多少条例select * from chinastates limit 10,1012.聚合函数(统计函数)(1)总数 count(*):查询数据总条数例select count(*) from chinastatescount(主键列 areacode)例select count(areacode) from chinastates(2)求和 sum(求价格和列)例select sum(price) from car(3)求平均 avg(求价格平均列)例select avg(price) from car(4)取最大值、最小值(价格列)例select max(price) from carselect min(price) from car13.分组查询 group by查询汽车表中每个系列下有多少汽车例select brand,count(*) from car group by brand查询汽车表中卖的汽车数量大于3的系列 注意: group by....having(条件)例select brand from car group by brand having count(*)3二、高级查询1.连接查询,对结果集列的扩展select * from info,nation #形成很大的冗余(笛卡尔积)多张表的列有重名的要写表名然后写列名格式如下表名.列名两种方式(1)select * from info,nation where info.nationnation.codeselect info.code,info.name,sex,nation.name,birthday from info,nation whereinfo.nationnation.code(2)select * from info join nation on info.nationnation.code2.联合查询对结果集行的扩展, 列的数量要相同 unionselect code,name from infounionselect code,name from nation3.子查询父查询外层查询子查询里查询(查询结果作为父查询的条件)(1)无关子查询子查询在执行时和父查询没有关系(子查询可单独执行)a.查询民族为汉族的所有人员信息父查询select * from info where nation()子查询select code from nation where name汉族合并后就是结果select * from info where nation(select code from nation where name汉族)b.查询系列名是“宝马5系”的所有汽车信息select * from car where brand(select brand_code from brand where brand_name宝马5系)(2)相关子查询子查询在执行时和父查询有关系(子查询不可单独执行)a.查询汽车表中油耗小于该系列平均油耗的所有汽车信息父查询select * from car where oil子查询select avg(oil) from car where brand该系列合并后就是结果select * from caras a where oil注意用as修改表名时不用加引号