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

html 网站 模板中文seo基础入门视频教程

html 网站 模板中文,seo基础入门视频教程,旅游景点介绍网页设计模板,潍坊企业网站建设子查询:类型、语法、和注意事项 使用子查询能解决哪些问题? 子查询语法: select select_list from table where expr operator (select select_list from table); 子查询(内查询)在主查询(外查询)之前执行。…

子查询:类型、语法、和注意事项


使用子查询能解决哪些问题?

wKioL1jHqvaAi5l5AABtYPakz2M348.jpg


子查询语法:

select select_list from table where expr operator (select select_list from table);

  • 子查询(内查询)在主查询(外查询)之前执行。

  • 主查询使用子查询结果。

  • 位置:select,where,from,having


1、查询谁的工资比Abel高

select last_name, salary from employees 

where salary >

(select salary

from employees

where last_name = 'Abel');

wKiom1jHsNqjz0PkAABsK2VriWA397.jpg


使用子查询注意事项

  • 子查询要包含在括号内。

  • 将子查询放在比较条件的右侧增强可读性(子查询可以出现在比较运算符的两侧)

  • 单行操作符对应单行子查询,多行操作符对应多行子查询


单行子查询:

– 子查询中的组函数

– HAVING 子句中的子查询


  • 只返回一行

  • 使用单行比较操作符


操作符含义
=等于
>大于
>=大于等于
<小于
<=小于等于
<>不等于


select last_name, job_id, salary from employees

where job_id  in  (select job_id from employees

where last_name like  'Taylor')

and salary in

(select salary

from employees

where last_name like 'Taylor');

wKiom1jHtBOQ7GOyAABwuTaqM_M121.jpg


在子查询中使用组函数

select last_name, job_id, salary from employees where 

salary = (select min(salary) from employees);

wKiom1jHtGeRiG-7AAA9uqj_8nk378.jpg



子查询中的HAVING 子句

  • 首先执行子查询

  • 向主查询中的 HAVING 子句返回结果

select department_id, min(salary)

from employees

group by department_id

having min(salary) >

(select min(salary)

from employees

where department_id = 50);

wKiom1jHtS7h4McRAABdKCs5ddg593.jpg


多行子查询使用单行比较符,以下为错误写法

select employee_id, last_name

from employees

where salary =

(select min(salary)

from employees

group by department_id);


子查询中的空值问题

wKioL1jHteXjowVRAAAq6WRkNzU513.jpg

select last_name, job_id from employees

where job_id =

(select job_id from employees

where last_name = 'haas');



多行子查询

– 使用 ALL 或 ANY


  • 返回多行。

  • 使用多行比较操作符。

操作符含义
IN等于列表中的任何一个值
ANY必须在=, !=, >, <, <=, >= 操作符之前使用,与列表中每个值进行比较,如果没有返回任何行,说明计算结果为FALSE
ALL必须在=, !=, >, <, <=, >=操作符之前使用,与列表中每个值进行比较,如果没有任何行返回,说明计算结果为TRUE


使用范例:

在多行子查询中使用 ANY 

select employee_id, last_name, job_id, salary

from employees  where salary < any

(select salary

from employees

where job_id = 'IT_PROG')

and job_id < > 'IT_PROG';

wKiom1jHt8LTA-IiAADQ_EwqKZw542.jpg


在多行子查询中使用 ALL  操作符

select employee_id, last_name, job_id, salary

from employees

where salary < all

(select salary

from employees

where job_id = 'IT_PROG')

and job_id <> 'IT_PROG';

wKioL1jHt6DD9JYjAADE2eDGWKo847.jpg


子查询中的空值

select emp.last_name

from employees emp

where emp.employee_id not in

(select mgr.manager_id

from employees mgr);



1、HR 部门的同事想要你帮忙写一个 SQL 语句,该 SQL 语句可以传入一个值(员工的 last_name),然后返回结果是该员工同一部门同事的 last_name 和 hire_date,且要求该员工不在返回结果中。

举个例子,如果用户输入”Zlotkey”,结果就会返回除了 Zlotkey 之外的同一部门的其他同事的

last_name 和 hire_date.


select last_name,hire_date

from employees

where department_id =(select department_id from employees

where last_name= '&&enter_name')

and last_name < > '&enter_name';


2、请查询出所有高于平均工资的员工的 employee_id,last_name,salary,并将最终结果根据salary 降序排列。

select employee_id,last_name,salary 

from employees 

where salary > (select avg(salary) 

            from employees) 

order by salary;


3、请写一条 SQL 语句,要求查询出那些同一部门员工 last_name 里面包含字母”u”的员工的employee_id,last_name。

select employee_id,last_name from employees where department_id in (select department_id from employees where last_name like '%u%');



4、请帮助HR部门的同事查出所有部门location_id是1700的员工的last_name,department_id,job_id。

select last_name,department_id,job_id

from employees

where department_id in(select department_id

from departments

where location_id=1700);


让用户可以选择输入一个 location_id,然后输出结果。

select last_name,department_id,job_id

from employees

where department_id in(select department_id

from departments

where location_id=&enter_location);


5、请查出所有需要向 King 汇报的员工的 last_name 以及 salary

select last_name,salary,manager_id

from employees

where manager_id = (select employee_id

from employees

where last_name like 'King' and manager_id is null);


6、请查出所有是执行部(Executive)的员工的 department_id,last_name,job_id

select department_id,last_name,job_id

from employees

where department_id in(select department_id

from departments

where department_name like 'Executive');


7、请查出比 department_id 是 60 的任何员工薪水高的所有的员工的 last_name。

select department_id,last_name,salary from employees 

where salary > any 

(select salary from employees

where department_id=60);


8、查询所有高于平均工资,并且同一部门员工 last_name 里面包含字母”u”的员工的 employee_id,last_name,salary。

select employee_id,last_name,salary

from employees

where department_id in(select department_id

from employees

where last_name like '%u%')

and salary > (select avg(salary) from employees);




本文转自 yuri_cto 51CTO博客,原文链接:http://blog.51cto.com/laobaiv1/1906425,如需转载请自行联系原作者

http://www.lbrq.cn/news/2737369.html

相关文章:

  • 青海高端网站建设价格百度搜索广告推广
  • 禁止wordpress自动更新优化关键词排名软件
  • 厦门做网站找哪家公司sem广告投放是做什么的
  • 出入库管理软件 免费seo流量优化
  • 如何搭建一个企业子账号网站独立站seo怎么做
  • 寻乌建设局网站邀请推广app
  • 网站怎么做才吸引人百度网站网址是多少
  • 武汉市内做网站的公司品牌建设
  • 文明网站建设方案及管理制度教育培训网站大全
  • 人社系统网站一体化建设方案seo是什么牌子
  • 老外做的汉语网站如何自己做一个网址
  • 网站可以做伦理片吗好省推广100种方法
  • 西安网站运营免费的外贸网站推广方法
  • 十四冶建设集团技工学校网站软文写作的技巧
  • 大理网站建设怎么在百度上发帖推广
  • 网站策划的重要性千牛怎么做免费推广引流
  • mvc5做博客网站百度搜索关键词排名靠前
  • 本地网站可以做吗如何创建微信小程序
  • 动态表白网站制作叶涛网站推广优化
  • 职高网站建设例题全面的seo网站优化排名
  • 单人做网站搜索引擎的网站
  • 广州seo工作室电池优化大师下载
  • 网站站点不安全电话销售如何快速吸引客户
  • 哪里有做鸭的网站企业网站建设哪家好
  • 黑龙江做网站的公司有哪些郑州网络推广专业公司
  • 网站高防空间杭州百度百科
  • 杭州聚翔网络有限公司seo客服
  • 建设网站的难点seo页面优化技术
  • 秦皇岛网站开发广州新闻报道
  • wordpress本地下载如何快速优化网站排名
  • VS Code配置MinGW64编译Ipopt库
  • 基于Uni-app+vue3实现微信小程序地图固定中心点范围内拖拽选择位置功能(分步骤详解)
  • 022 基础 IO —— 文件
  • Javar如何用RabbitMQ订单超时处理
  • 【完整源码+数据集+部署教程】孔洞检测系统源码和数据集:改进yolo11-RetBlock
  • 【数据分享】2022 年黑龙江省小麦、玉米和水稻幼苗影像数据集