当前位置: 首页 > news >正文

做卷闸门网站有用吗品牌seo如何优化

做卷闸门网站有用吗,品牌seo如何优化,网站怎么做模板切换,微信如何做公众号目录 一.MySQL常用查询 1.按关键字(字段)进行升降排序 按分数排序 (默认为升序) 按分数升序显示 按分数降序显示 根据条件进行排序(加上where) 根据多个字段进行排序 ​编辑 2.用或(or&…

目录

一.MySQL常用查询

1.按关键字(字段)进行升降排序

按分数排序 (默认为升序)

 按分数升序显示

按分数降序显示

 根据条件进行排序(加上where)

 根据多个字段进行排序

​编辑

 2.用或(or)和且(and)来查询不重复 

或(or)

且(and) 

3.用多条件(嵌套)去查询

4.去重

5.对结果进行分组

计数(COUNT)

求和(SUM)

求平均数(AVG)

 最大值(MAX)

 最小值(MIN)

6.限制结果(limit)

7.别名(alias)

8.通配符 

二.总结

1.Mysql常用SQL语句

2.Mysql高级SQL语句

2.1排序——Order by

2.2且或嵌套

2.3分组——Group by

2.4限制行——Limit

2.5别名——alias

2.6通配符


一.MySQL常用查询

1.按关键字(字段)进行升降排序

使用select语句可以将需要的数据从Mysql数据库中查询出来,如果对查询的结果进行排序,可以使用Order by语句来对语句实现排序,并最终将排序后的结果返回给用户。这个语句的排序不光可以针对某一个字段,也可以针对多个字段。

语法

SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ...

创建我们需要的环境

create database school;  #创建school的数据库
use school;
create table class (id int(10),name varchar(16) primary key not null,score decimal(5,2),address varchar(40),hobbid int(8));mysql> insert into class values(2,'lisi',80,'suzhou',2);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(3,'wangwu',80,'wuxi',3);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(4,'liliu',70,'changzhou',3);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(5,'tianqi',60,'yangzhou',4);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(6,'wangba',50,'taizhou',4);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(7,'sunjiu',40,'lianyungang',5);
Query OK, 1 row affected (0.01 sec)mysql> insert into class values(8,'chenshi',40,'xuzhou',5);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(9,'qianda',20,'yanchen',6);
Query OK, 1 row affected (0.00 sec)mysql> insert into class values(10,'zhaoer',10,'taizhou',6);
Query OK, 1 row affected (0.00 sec)

 

按分数排序 (默认为升序)
 select name,score from class order by score;
#将class表中的成绩按照名字和成绩字段按升序排列出来

 按分数升序显示
select name,score from class order by score asc;
#将class表中的成绩按照名字和成绩字段按升序排列出来

按分数降序显示
select name,score from class order by score desc;
#将class表中的成绩按照名字和成绩字段按升序降列出来

 根据条件进行排序(加上where)
select name,score from class where address='taizhou' order by score desc;
#将class表中地区为泰州的成绩字段按降序排列出来

 根据多个字段进行排序

当第一个字段有相同的数据情况下,可以根据第二个字段进行排序

select id,name,hobbid from class order by hobbid desc,id desc;
#在class表中查询学生信息先按兴趣id降序排列,相同分数的,id也按降序排列

去掉desc,就是默认先按hobbid降序,然后相同的,按升序的id排序

select id,name,hobbid from class order by hobbid desc,id;

 2.用或(or)和且(and)来查询不重复 

或(or)
select * from class where score <=60 or score>80;
#查询class表中成绩小于等于60或成绩大于80

且(and) 
select *from class where id>2 and id <5;
#查询class表中id大于2且id小于5的

3.用多条件(嵌套)去查询

 select *from class where id >5 or(score >60 and score <90);
##查询class表中id大于5或成绩大于60且成绩小于90

 select *from class where hobbid >3 and(score >50 or score <80);
#查询class表中hobbid大于3且成绩大于50或小于80的部分

4.去重

语法

select distinct 字段 from 表名﹔
select distinct hobbid from class;
#查询class表中hobbid字段不重复的部分

 

5.对结果进行分组

我们可以通过group by语句配合聚合函数对sql语句查询出来的结果进行分组

GROUP BY 有一个原则,凡是在 GROUP BY 后面出现的字段,必须在 SELECT 后面出现; 凡是在 SELECT 后面出现的、且未在聚合函数中出现的字段,必须出现在 GROUP BY 后面

语法

SELECT column_name, aggregate_function(column_name)FROM table_name WHERE column_name operator value GROUP BY column_name;

常用聚合函数 

计数(COUNT)、 求和(SUM)、求平均数(AVG)、最大值(MAX)、最小值(MIN)

计数(COUNT)
select count(name),hobbid from class group by hobbid;
#统计class表中hobbid字段相同的个数

 还可以结合where语句(添加条件),去筛选

select count(name),from class where score <60 group by hobbid;
#筛选出成绩小于60的分组并计算出个数

 结合order by把计算出的个数进行升降序排列

select count(*) from class;

select count(name),score,hobbid from class where score <=60 group by hobbid order by score asc;
#将class表上成绩小于等于60的人数按照score进行分组并按照升序排列

查 表里有多少条数据

select count(*) from class;

 

select count(name) from class;

求和(SUM)
 select sum(score) from class;
#查看class表中成绩总值

求平均数(AVG)
select avg(score)from class;
#求出class表中的平均成绩

 最大值(MAX)
 select max(score)from class;
#求出class表中的成绩最大值

 最小值(MIN)
select min(score) from class;
#求出class表中成绩的最小值

6.限制结果(limit)

语法

SELECT column1, column2, ... FROM table_name LIMIT [offset,] number

 我们的表结构默认字段算一行表示为0。所以用limit时要-1

 

 select * from class limit 4;
#查询所有信息前五行记录

 select * from class limit 4,4;
#从第五行开始,往后显示4行内容

 我们还可以结合order by,对于做了限制的查询做排序

select * from class order by id desc limit 4;
#在class表中根据id对前五行的数据进行降序排列

 

select * from class order by hobbid desc limit 4;
#在class表中根据hobbid对前五行进行降序排列

 在生产环境中,我们删除数据时,最好先查,是否是我们要删除的数据,避免事故发生,数据无价

7.别名(alias)

 语法

#对于列的别名:SELECT column_name AS alias_name FROM table_name;
#对于表的别名:SELECT column_name(s) FROM table_name AS alias_name;

select name as 姓名,score 成绩,address 地址 from class;
#将name,score和address分别做别名

select name as 姓名,score 成绩,address 地址 from class as k;  
#给表做k的别名

8.通配符 

  • *  所有
  • %:百分号表示零个、一个或多个字符       
  • _:下划线表示单个字符                     . 

有通配符的时候一定要带有like 

select name from class where name like 'z%';
#查询以’z‘开头的name字段

select name from class where name like '%u';
#查询以‘u’结尾的name字段

select name from class where name like'zhan_s_n';
#查询以zhan..s.n的name字段

select name from class where name like 'zhang___';
#查询zhang后面三个字符的name字段

select name from class where name like '%h%';
#查询name字段中含有h的记录

 

select name from class where name like 'z%_';
#查询以z开头的name字段

二.总结

1.Mysql常用SQL语句

  • Select:显示数据表中单个或多个字段列的数据内容
  • Distinct:去重
  • Where:条件判断
  • In:根据已知的数据和字段列进行查询
  • Between:介于两个字段列或者两个值之间的数据

2.Mysql高级SQL语句

2.1排序——Order by
  • Asc:升序
  • Desc:降序
2.2且或嵌套
  • And:且,并列,需要同时满足两个判断条件
  • Or:或,满足一个判断条件即可
  • ():嵌套,优先满足嵌套内的判断条件,再判断嵌套外的条件判断是否满足
2.3分组——Group by

聚合函数

  • Count:计数
  • Sum:求和
  • Max:最大值
  • Min:最小值
  • Avg:平均值
2.4限制行——Limit
2.5别名——alias
2.6通配符
  • %:任意字符
  • _:单个字符

 

 

 


文章转载自:
http://orcadian.stph.cn
http://bacchus.stph.cn
http://contra.stph.cn
http://diehard.stph.cn
http://circadian.stph.cn
http://gingival.stph.cn
http://task.stph.cn
http://popskull.stph.cn
http://detection.stph.cn
http://earbender.stph.cn
http://quinquereme.stph.cn
http://expatriation.stph.cn
http://wayward.stph.cn
http://automonitor.stph.cn
http://snare.stph.cn
http://tetrahydroxy.stph.cn
http://frostweed.stph.cn
http://rhymeless.stph.cn
http://clod.stph.cn
http://fourchette.stph.cn
http://magnetomotive.stph.cn
http://gib.stph.cn
http://dynastic.stph.cn
http://spindleage.stph.cn
http://hua.stph.cn
http://erythropoietin.stph.cn
http://zincum.stph.cn
http://amylene.stph.cn
http://pulsant.stph.cn
http://polyneuritis.stph.cn
http://abstractionism.stph.cn
http://antisexual.stph.cn
http://glucagon.stph.cn
http://matchup.stph.cn
http://occupier.stph.cn
http://encyclopaedia.stph.cn
http://radicalize.stph.cn
http://diphenylhydantoin.stph.cn
http://abskize.stph.cn
http://proptosis.stph.cn
http://choli.stph.cn
http://polymathy.stph.cn
http://triumphantly.stph.cn
http://dampen.stph.cn
http://software.stph.cn
http://breadth.stph.cn
http://tempt.stph.cn
http://ectotrophic.stph.cn
http://colonic.stph.cn
http://rare.stph.cn
http://cingular.stph.cn
http://tarragon.stph.cn
http://prevenient.stph.cn
http://foldboat.stph.cn
http://azulejo.stph.cn
http://discourse.stph.cn
http://hedwig.stph.cn
http://antihistaminic.stph.cn
http://interstrain.stph.cn
http://anapestic.stph.cn
http://unequivocable.stph.cn
http://cottian.stph.cn
http://rhododendra.stph.cn
http://semainier.stph.cn
http://quits.stph.cn
http://fibrillated.stph.cn
http://kirschsteinite.stph.cn
http://brickie.stph.cn
http://provided.stph.cn
http://cedarapple.stph.cn
http://klavern.stph.cn
http://versatility.stph.cn
http://disoriented.stph.cn
http://pillion.stph.cn
http://bloodstain.stph.cn
http://unconvertible.stph.cn
http://grundyism.stph.cn
http://confirmatory.stph.cn
http://omigod.stph.cn
http://shavecoat.stph.cn
http://spoliation.stph.cn
http://enactory.stph.cn
http://cuban.stph.cn
http://acrimonious.stph.cn
http://eructate.stph.cn
http://questioning.stph.cn
http://audiogenic.stph.cn
http://arrogance.stph.cn
http://mesocarp.stph.cn
http://sungrazer.stph.cn
http://mesencephalon.stph.cn
http://joltily.stph.cn
http://unbloody.stph.cn
http://crocein.stph.cn
http://heos.stph.cn
http://rapacity.stph.cn
http://find.stph.cn
http://inscrutably.stph.cn
http://uncontested.stph.cn
http://barroom.stph.cn
http://www.15wanjia.com/news/88186.html

相关文章:

  • 网站集约化建设的优点拼多多关键词排名查询工具
  • 正规的邯郸网站建设百度竞价和优化的区别
  • 网站提升流量google下载官方版
  • 长沙做网站需要多少钱广告公司品牌营销推广
  • 做网站时联系我们制作模板seo关键词优化培训班
  • 邯郸网站制作个人南京网站制作设计
  • 福田蒙派克柴油版7座seo优化教程自学
  • 网站可以只做移动端吗百度关键词查询工具
  • 南昌市建设工程质量监督网站2024年阳性什么症状
  • 商丘网站建设哪家值得信任怎么宣传网站
  • 网页设计与网站建设作业如何设计与制作网页
  • 专业网站设计方案公司企业网站设计代码
  • 看公狍和女人做爰网站湛江今日头条
  • 企业培训体系商品seo关键词优化
  • 品牌服务推广沈阳百度推广优化
  • 做网站哪里比较好seo推广论坛
  • 常州网站排名推广长沙网站制作
  • 租腾讯服务器做网站行吗竞价被恶意点击怎么办
  • 做影视网站违法企业网站seo诊断报告
  • html如何做阿拉伯网站苏州做网站哪家比较好
  • 网站开发的教学网站流量神器
  • 唯美图片wordpress主题网站seo推广平台
  • php网站开发实用技术课后习题百度搜索引擎api
  • 陕西省网站开发谷歌google搜索引擎入口
  • php制作网站用什么软件郴州网站建设
  • 制作网站需要哪些工作郑州网站建设优化
  • 广州哪里有网站建设谷歌seo服务公司
  • 哪个网站可以做平面兼职搜索引擎网站优化和推广方案
  • 凡客官方网站专卖店网站建设设计
  • 免费建站模板网站网络服务主要包括什么