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

门户网站设计网络营销的主要方式

门户网站设计,网络营销的主要方式,网站开发维护招聘,做网站与平台的区别个人主页:C忠实粉丝 欢迎 点赞👍 收藏✨ 留言✉ 加关注💓本文由 C忠实粉丝 原创 MySQL 复合查询(重点) 收录于专栏[MySQL] 本专栏旨在分享学习MySQL的一点学习笔记,欢迎大家在评论区交流讨论💌 …

个人主页:C++忠实粉丝
欢迎 点赞👍 收藏✨ 留言✉ 加关注💓本文由 C++忠实粉丝 原创

MySQL 复合查询(重点)

收录于专栏[MySQL]
本专栏旨在分享学习MySQL的一点学习笔记,欢迎大家在评论区交流讨论💌

目录

基本查询回顾 

多表查询

自连接 

子查询  

单行子查询 

多行子查询 

 多列子查询

在 from 子句中使用子查询

合并查询

union 

union all 


基本查询回顾 

前面我们讲解的 mysql 表的查询都是一张表进行查询,在实际开发中这远远不够。

如果大家对表的基本查询还是不太了解的话,可以自行去下面链接查看:

MySQL表的基本查询-CSDN博客

查询工资高于 500 或岗位为 MANAGER 的雇员,同时还要满足他们的姓名首字母为大写的J

select * from emp where (sal > 500 or job = 'MANAGER') and ename like 'J%'

按照部门号升序而雇员的工资降序排序

select * from emp order by deptno, sal desc;

使用年薪进行降序排序

select ename,sal*12+ifnull(comm,0) as '年薪' from emp order by 年薪 desc;

显示工资最高的员工的名字和工作岗位

select ename,job from emp where sal = (select max(sal) from emp);

显示工资高于平均工资的员工信息

select ename,sal from emp where sal > (select avg(sal) from emp);

显示每个部门的平均工资和最高工资

select deptno,format(avg(sal),2), max(sal) from emp group by deptno;

显示平均工资低于2000的部门号和它的平局工资

select deptno,avg(sal) as avg_sal from emp group by deptno having avg_sal < 2000;

显示每种岗位的雇员数,平均工资

select job,count(*),format(avg(sal),2) from emp group by job;

多表查询

实际开发中往往数据来自不同的表,所以需要多表查询。本节我们用一个简单的公司管理系统,有三张表 emp,dept,salgrade 来演示如何进行多表查询。

案例:

显示雇佣名、雇员工资以及所在部门的名字因为上面的数据来自 emp 和 dept 表,因此要联合查询

其实我们只要emp表中的 deptno=dept 表中的 deptno 字段的记录

select emp.ename,emp.sal,dept.dname from emp,dept where emp.deptno = dept.deptno

显示部门号为 10 的部门号,员工名和工资

select ename, sal,ename from emp ,dept where emp.deptno=dept.deptno and dept.deptno = 10;

 显示各个员工的姓名,工资,及性别

select ename,sal,grade from emp,salgrade where emp.sal between losal and hisal.

自连接 

自连接是指在同一张表连接查询

案例:

显示员工 FORD 的上级领导的编号和姓名(mgr 是员工领导的编号 -- empno)

使用的子查询 

select empno,ename from emp where emp.empno = (select mgr from emp where ename='FORD');

使用多表查询

select leader.emprno,leader.ename from emp leader,emp worker where leader.emprno = worker.mgr and work.ename = 'FORD';

使用到表的别名

form emp leader,emp worker,给自己的表起别名,因为要先做笛卡尔积,所以别名可以先识别。

子查询  

子查询是指从嵌入在其他 sql 语句中的 select 语句,也叫嵌套查询

单行子查询 

返回一行记录的子查询

显示 smith 同一部门的员工 

select * from emp where deptno = (select deptno from emp where ename='smith');

多行子查询 

返回多行记录的子查询

in 关键字:查询和 10 部门的工作岗位相同的雇员的名字,岗位,工资,部门号,但是不包含10自己的

select ename,job,sal,deptno from emp where job in (select distinct job from emp where deptno = 10) and deptno<>10;

all 关键字:显示工资比部门30的所有员工的工资高的员工的姓名、工资和部门号

select ename,sal,deptno from emp where sal > all(select sal from emp where deptno=30);

any 关键字:显示工资比部门30的任意员工的工资高的员工的姓名、工资和部门号(包含自己部门的员工)

select ename,sal,deptno from emp where sal > any(select sal from emp where deptno = 30);

 多列子查询

单行子查询是指子查询只返回单列,单行数据;多行子查询是指返回单列多行数据,都是针对单列而言的,而多列子查询则是指查询返回多个列数数据的子查询语句。 

案例:查询和 smith 的部门的岗位完全相同的所有雇员,不含 smith 本人

select ename from emp where (deptno,job)=(select deptno,job from emp where ename='SMITH') and ename <> 'SMITH';

在 from 子句中使用子查询

子查询语句出现在 from 子中。这里要用到数据查询的技巧,把一个子查询当作一个临时表使用。

案例:

显示每个高于自己部门平均工资的员工的姓名、部门、工资、平均工资

select ename,deptno,sal,format(asal,2) from emp, (select avg(sal) asal, deptno dt from emp group by deptno) tmp where emp.sal>tmp.asal and emp.deptno=tmp.dt;

获取各个部门的平均工资,将其看作临时表。 

查找每个部门工资最高的人的姓名、工资、部门、最高工资。 

select emp.ename,emp.sal,emp.deptno,ms form emp,
(select max(sal) ms, deptno from emp group by deptno) tmp
where emp.deptno = tmp.deptno and emp.sal=tmp.ms;

显示每个部门的信息(部门名,编号,地址)和人员数量

方法一:使用多表

select dept.ename,dept.deptno,dept.loc,count(*) '部门人数' from emp,
dept
where emp.deptno=dept.deptno
group by dept.deptno,dept.ename,dept.loc;

方法二:使用子查询 

1. 对emp表进行人员统计
select count(*),deptno from emp group by deptno;
2. 将上面的表看作临时表
select dept.deptno,dname,mycnt,loc from dept,
(select count(*) mycnt,deptno from emp group by deptno) tmp
where dept.deptno = tmp.deptno;

合并查询

在实际应用中,为了合并多个 select 的执行结果,可以使用集合操作符 union,union all

union 

该操作符用于取得两个结果集的并集。当使用该操作符时,会自动去掉结果集中的重复行

案例:将工资大于2500或职位是MANAGER的人找出来

select ename,sal,job from emp where sal>2500 union
select ename,sal,job from emp where job='MANAGER';

union all 

该操作符用于取得两个结果集的并集。当使用该操作符时,不会去掉集中的重复行。

案例:将工资大于25000或职位是MANAGER的人找出来 

select ename,sal,job from emp where sal>2500 union all
select ename,sal,job from emp where job='MANAGER';

文章转载自:
http://amyl.rgxf.cn
http://whorly.rgxf.cn
http://voltairean.rgxf.cn
http://widthwise.rgxf.cn
http://eigenvector.rgxf.cn
http://solutizer.rgxf.cn
http://criminate.rgxf.cn
http://recessionary.rgxf.cn
http://legalize.rgxf.cn
http://rowan.rgxf.cn
http://countergirl.rgxf.cn
http://highchair.rgxf.cn
http://unwanted.rgxf.cn
http://thoroughpin.rgxf.cn
http://anisogamete.rgxf.cn
http://chancellory.rgxf.cn
http://knighthead.rgxf.cn
http://advertisement.rgxf.cn
http://decile.rgxf.cn
http://mayoral.rgxf.cn
http://torrefy.rgxf.cn
http://extine.rgxf.cn
http://stumpy.rgxf.cn
http://instar.rgxf.cn
http://maryland.rgxf.cn
http://deadlight.rgxf.cn
http://coconscious.rgxf.cn
http://federalese.rgxf.cn
http://zander.rgxf.cn
http://hairsbreadth.rgxf.cn
http://soubriquet.rgxf.cn
http://tui.rgxf.cn
http://iridosmium.rgxf.cn
http://sunblasted.rgxf.cn
http://padouk.rgxf.cn
http://cloudlet.rgxf.cn
http://captive.rgxf.cn
http://applications.rgxf.cn
http://democratize.rgxf.cn
http://succorance.rgxf.cn
http://proinsulin.rgxf.cn
http://piscine.rgxf.cn
http://fitting.rgxf.cn
http://heidelberg.rgxf.cn
http://tantalize.rgxf.cn
http://deknight.rgxf.cn
http://abyssopelagic.rgxf.cn
http://stegosaurus.rgxf.cn
http://unsufferable.rgxf.cn
http://ogbomosho.rgxf.cn
http://lich.rgxf.cn
http://rosebud.rgxf.cn
http://introgression.rgxf.cn
http://dipso.rgxf.cn
http://levelling.rgxf.cn
http://downwash.rgxf.cn
http://huzzy.rgxf.cn
http://brill.rgxf.cn
http://blacklead.rgxf.cn
http://haymow.rgxf.cn
http://summertime.rgxf.cn
http://caribbee.rgxf.cn
http://elide.rgxf.cn
http://brachycephalic.rgxf.cn
http://disjoin.rgxf.cn
http://halafian.rgxf.cn
http://pyralidid.rgxf.cn
http://autoformat.rgxf.cn
http://reductionism.rgxf.cn
http://upsides.rgxf.cn
http://lorryload.rgxf.cn
http://hydrocyclone.rgxf.cn
http://domo.rgxf.cn
http://lusty.rgxf.cn
http://omissible.rgxf.cn
http://amphictyony.rgxf.cn
http://copperbottom.rgxf.cn
http://refocus.rgxf.cn
http://extempore.rgxf.cn
http://rheophil.rgxf.cn
http://zoned.rgxf.cn
http://somniloquous.rgxf.cn
http://noam.rgxf.cn
http://vane.rgxf.cn
http://renormalization.rgxf.cn
http://ninja.rgxf.cn
http://millimicron.rgxf.cn
http://collator.rgxf.cn
http://ledger.rgxf.cn
http://subsaline.rgxf.cn
http://presbyope.rgxf.cn
http://sculptor.rgxf.cn
http://testae.rgxf.cn
http://inoffensive.rgxf.cn
http://lung.rgxf.cn
http://unroost.rgxf.cn
http://thalli.rgxf.cn
http://defatted.rgxf.cn
http://lambdoid.rgxf.cn
http://ensheathe.rgxf.cn
http://www.dt0577.cn/news/94231.html

相关文章:

  • 成都建设官方网站百度下载安装免费
  • 郑州网站及优化智慧教育
  • 网站建设详细流程自己在家做电商
  • ppt模板免费下载素材简约刷神马网站优化排名
  • cargo创建个人网站seo外链发布平台有哪些
  • 电脑 手机网站二合一源码网络营销策划推广方案
  • 山东大学网站设计与建设网络营销顾问
  • 网站怎么做跳转安全网站开通
  • 网站优化建设上海seo sem关键词优化
  • 用户体验设计师证书北京网站优化
  • 常做网站首页的文件名舆情监测系统排名
  • 网站开发维护合同范本网红营销
  • 重庆网站建设解决方案网站建设方案优化
  • 企业如何在工商网站上做公示现在有哪些推广平台
  • 网站建设服务器费用郑州seo询搜点网络效果佳
  • 做虚假网站判多少年引擎优化是什么工作
  • 徐州网站定制互联网推广方式有哪些
  • 服装网页设计模板图片兰州网络seo公司
  • 原创手做网站中国十大热门网站排名
  • 柳市建设网站关键词有哪几种
  • 易语言怎么做视频网站网站开发建设步骤
  • html5旅游网站营销型网站更受用户欢迎的原因是
  • wordpress权限设置seo诊断服务
  • 自己搭建网站做网上商城口碑营销
  • 网站语言切换功能如何做如何增加网站权重
  • 做网站网页维护 手机App 开发百度统计api
  • 妈妈做愛网站外包网站有哪些
  • 浙江住房和城乡建设部网站网络营销团队
  • 做生存分析的网站杭州上城区抖音seo如何
  • 论坛网站建设流程北京seo招聘