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

可以用qq登陆的wordpress聊城网站建设优化

可以用qq登陆的wordpress,聊城网站建设优化,网站做新浪图床,邵阳做网站哪家好一、set运算符 union:得到两个查询结果的并集,并且⾃动去掉重复⾏。不会排序 union all:得到两个查询结果的并集,不会去掉重复⾏。也不会排序 intersect:得到两个查询结果的交集,并且按照结果集的第⼀个列进…

一、set运算符

set操作符
union:得到两个查询结果的并集,并且⾃动去掉重复⾏。不会排序
union all:得到两个查询结果的并集,不会去掉重复⾏。也不会排序
intersect:得到两个查询结果的交集,并且按照结果集的第⼀个列进⾏排序
minus:得到两个查询结果的减集,以第⼀列进⾏排序

--查询部门的部门号,其中不包括job_id是”ST_CLERK”的部门号
select department_id
from departments
minus
select department_id
from employees
where job_id = 'ST_CLERK'
--查询10,50,20号部门的job_id,department_id
--并且department_id按10,50,20的顺序排列
column a_dummy noprint	--隐藏后面的1、2、3(序列号)select job_id,department_id,1 a_dummy
from employees
where department_id = 10
union
select job_id,department_id,2
from employees
where department_id = 50
union
select job_id,department_id,3
from employees
where department_id = 20
order by 3	--使用order by对结果集排序
--查询所有员工的last_name ,department_id 和department_name
select last_name,department_id,to_char(null) department_name
from employees
union
select to_char(null),department_id,department_name
from departments

二、高级子查询

1.多列子查询

多列子查询中的比较分为两种:成对比较、不成对比较

成对比较

--查询与141号或174号员工的manager_id和department_id相同的
--其他员工的employee_id, manager_id, department_id
select employee_id,manager_id,department_id
from employees
where (manager_id,department_id) in (select manager_id,department_idfrom employeeswhere employee_id in (141,174))
and employee_id not in (141,174)

不成对比较

select employee_id,manager_id,department_id
from employees
where manager_id in (select manager_idfrom employeeswhere employee_id in (141,174))
and department_id in (select department_idfrom employeeswhere employee_id in (141,174))
and employee_id not in (141,174)

2.在 FROM 子句中使用子查询

案例对比:

--返回比本部门平均工资高的员工的last_name, department_id, salary及平均工资
select last_name,department_id,salary,
(select avg(salary) from employees e3 where e1.department_id = e3.department_id group by department_id) avg_sal
from employees e1
where salary > (select avg(salary)from employees e2where e1.department_id = e2.department_idgroup by department_id)
--在 FROM 子句中使用子查询
--返回比本部门平均工资高的员工的last_name, department_id, salary及平均工资
select last_name,e1.department_id,salary,e2.avg_sal
from employees e1,(select department_id,avg(salary) avg_sal from employees group by department_id) e2
where e1.department_id = e2.department_id
and e1.salary > e2.avg_sal

由上可知,在 FROM 子句中使用子查询可以减少冗余

3.单列子查询

<1>在 CASE 表达式中使用单列子查询

--显示员工的employee_id,last_name和location。
--其中,若员工department_id与location_id为1800的department_id相同,则location为’Canada’
--其余则为’USA’。
select employee_id,last_name,
(case department_id when (select department_id from departments where location_id = 1800) then 'Canada'else 'USA' end) location
from employees

<2>在 ORDER BY 子句中使用单列子查询

--查询员工的employee_id,last_name,要求按照员工的department_name排序
select employee_id,last_name
from employees e
order by (select department_namefrom departments dwhere e.department_id = d.department_id) asc

4.相关子查询

子查询中使用主查询中的列,主查询的每一行都执行一次子查询

--查询员工中工资大于本部门平均工资的员工的last_name,salary和其department_id
select last_name,salary,department_id
from employees e1
where salary > (select avg(salary)from employees e2where e1.department_id = e2.department_id)
--若employees表中employee_id与job_history表中employee_id相同的数目不小于2,
--输出这些相同id的员工的employee_id,last_name和其job_id
select employee_id,last_name,job_id
from employees e
where 2 <= (select count(1)from job_historywhere e.employee_id = employee_id )

5.EXISTS操作符和NOT EXISTS操作符

EXISTS 操作符检查在子查询中是否存在满足条件的行
如果满足条件则输出
NOT EXISTS操作符正好相反

--查询公司管理者的employee_id,last_name,job_id,department_id信息
select employee_id,last_name,job_id,department_id
from employees mgr
where exists(select 'A'from employees empwhere mgr.employee_id = emp.manager_id)
--查询departments表中,不存在于employees表中的部门的department_id和department_name
select department_id,department_name
from departments d
where not exists(select 'A'from employeeswhere department_id = d.department_id)

6.WITH 子句

使用 WITH 子句, 可以避免在 SELECT 语句中重复书写相同的语句块
WITH 子句将该子句中的语句块执行一次并存储到用户的临时表空间中
使用 WITH 子句可以提高查询效率

--查询公司中各部门的总工资大于公司中各部门的平均总工资的部门信息
with dept_sumsal as(
select department_name,sum(salary) sum_sal
from employees e,departments d
where e.department_id = d.department_id
group by department_name
),
dept_avgsal as(
select sum(sum_sal)/count(1) avg_sum_sal
from dept_sumsal
)select *
from dept_sumsal
where sum_sal > (select avg_sum_salfrom dept_avgsal)
order by department_name
http://www.yayakq.cn/news/654971/

相关文章:

  • 外贸企业网站系统源码wordpress 4.5.3 主题
  • 购物网站排名前100怎么安装的wordpress主题
  • 先看网站案例您的网站也可以这么做招设计师在哪里找
  • 网站制作框架怎么建网站教程视频
  • 网站后台模板 如何使用二手车网站策划
  • 网站竞争对手合肥经开区建设局网站
  • 灵犀科技 高端网站建设背景图互联网创业项目整合网站
  • 军事网址大全 网站百度搜不到WordPress文章
  • 专门做淘宝代运营的网站贸易网站有哪些
  • 机械营销网站建设案例石家庄网站制作招聘
  • 无锡网页建站社群营销是什么意思
  • 大型网站建立wamp 怎么做两个网站
  • 怎么做文学动漫网站在线生成固定悬浮导航的工具网站
  • 网站建设征求意见wordpress vip会员主题
  • 天河做网站平台中国最新军事新闻最新消息2023
  • 视频上传网站建设中国建设银行集团网站
  • 河南金建建设有限公司网站wordpress英文显示改中文字体
  • 重庆商业网站有哪些学大教育培训机构怎么样
  • 企业网站建设代码杭州网站建设哪个平台好
  • 部门网站建设工作总结网站建设模板犀牛云
  • 小型网站搭建徐州比居网络科技有限公司
  • 如何选择网站做站方向网上做网站任务
  • 网站建设所需域名网站优化专家
  • 宁波网站推广有关做聚合物电池公司的网站
  • 网站建设规划方案包括天津数字防疫
  • 湖南网站建设 莫道手机购物网站怎么推广
  • 青海网站如何建设天津百度推广排名
  • 如何做一张网站平面效果图江苏建设信息网证书查询电子证书
  • 南京斯点企业网站建设郑州seo学校
  • 软件下载网站哪个比较好seo 推广怎么做