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

seo站长综合查询工具微信企业邮箱怎么注册

seo站长综合查询工具,微信企业邮箱怎么注册,建设网站费用入会计分录,摄影作品网站知乎复合查询目录 一、基本查询二、多表查询三、自连接四、子查询4.1 单行子查询4.2 多行子查询4.3 多列子查询4.4 在from子句中使用子查询4.5 合并查询4.5.1 union4.5.2 union all 五、实战OJ 一、基本查询 --查询工资高于500或岗位为MANAGER的雇员#xff0c;同时还要满足他们的… 复合查询目录 一、基本查询二、多表查询三、自连接四、子查询4.1 单行子查询4.2 多行子查询4.3 多列子查询4.4 在from子句中使用子查询4.5 合并查询4.5.1 union4.5.2 union all 五、实战OJ 一、基本查询 --查询工资高于500或岗位为MANAGER的雇员同时还要满足他们的姓名首字母为大写的J mysql select * from emp where (sal500 or jobMANAGER)and ename like J%; -------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | -------------------------------------------------------------------------- | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950.00 | NULL | 30 | -------------------------------------------------------------------------- 2 rows in set (0.00 sec) --按照部门号升序而雇员的工资降序排序 mysql select * from emp order by deptno, sal desc; -------------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | -------------------------------------------------------------------------------- | 007839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 007782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | NULL | 10 | | 007934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | NULL | 10 | | 007788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 007902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007876 | ADAMS | CLERK | 7788 | 1987-05-23 00:00:00 | 1100.00 | NULL | 20 | | 007369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800.00 | NULL | 20 | | 007698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | NULL | 30 | | 007499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600.00 | 300.00 | 30 | | 007844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500.00 | 0.00 | 30 | | 007521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250.00 | 500.00 | 30 | | 007654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 | 30 | | 007900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950.00 | NULL | 30 | -------------------------------------------------------------------------------- 14 rows in set (0.00 sec)--使用年薪进行降序排序 mysql select ename,sal*12ifnull(comm,0) as 年薪 from emp order by 年薪 desc; ------------------ | ename | 年薪 | ------------------ | KING | 60000.00 | | SCOTT | 36000.00 | | FORD | 36000.00 | | JONES | 35700.00 | | BLAKE | 34200.00 | | CLARK | 29400.00 | | ALLEN | 19500.00 | | TURNER | 18000.00 | | MARTIN | 16400.00 | | MILLER | 15600.00 | | WARD | 15500.00 | | ADAMS | 13200.00 | | JAMES | 11400.00 | | SMITH | 9600.00 | ------------------ 14 rows in set (0.00 sec) --显示工资最高的员工的名字和工作岗位 mysql select ename,job from emp where sal(select max(sal) from emp); ------------------ | ename | job | ------------------ | KING | PRESIDENT | ------------------ 1 row in set (0.01 sec) --显示工资高于平均工资的员工信息 mysql select * from emp where sal(select avg(sal) from emp); ---------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | ---------------------------------------------------------------------------- | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | NULL | 30 | | 007782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | NULL | 10 | | 007788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 007839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 007902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | ---------------------------------------------------------------------------- 6 rows in set (0.00 sec) --显示每个部门的平均工资和最高工资 mysql select deptno,format(avg(sal),2),max(sal) from emp group by deptno; -------------------------------------- | deptno | format(avg(sal),2) | max(sal) | -------------------------------------- | 10 | 2,916.67 | 5000.00 | | 20 | 2,175.00 | 3000.00 | | 30 | 1,566.67 | 2850.00 | -------------------------------------- 3 rows in set (0.01 sec) --显示平均工资低于2000的部门号和它的平均工资 mysql select deptno,avg(sal) as avg_sal from emp group by deptno having avg_sal2000; --------------------- | deptno | avg_sal | --------------------- | 30 | 1566.666667 | --------------------- 1 row in set (0.00 sec) --显示每种岗位的雇员总数平均工资 mysql select job,count(*),format(avg(sal),2) from emp group by job; ----------------------------------------- | job | count(*) | format(avg(sal),2) | ----------------------------------------- | ANALYST | 2 | 3,000.00 | | CLERK | 4 | 1,037.50 | | MANAGER | 3 | 2,758.33 | | PRESIDENT | 1 | 5,000.00 | | SALESMAN | 4 | 1,400.00 | ----------------------------------------- 5 rows in set (0.00 sec) 二、多表查询 实际开发中往往数据来自不同的表所以需要多表查询。本节我们用一个简单的公司管理系统有三张表EMP,DEPT,SALGRADE来演示如何进行多表查询。笛卡尔积 案例 --显示雇员名、雇员工资以及所在部门的名字因为上面的数据来自EMP和DEPT表因此要联合查询 mysql select ename,sal,dname from emp,dept where emp.deptnodept.deptno; ----------------------------- | ename | sal | dname | ----------------------------- | SMITH | 800.00 | RESEARCH | | ALLEN | 1600.00 | SALES | | WARD | 1250.00 | SALES | | JONES | 2975.00 | RESEARCH | | MARTIN | 1250.00 | SALES | | BLAKE | 2850.00 | SALES | | CLARK | 2450.00 | ACCOUNTING | | SCOTT | 3000.00 | RESEARCH | | KING | 5000.00 | ACCOUNTING | | TURNER | 1500.00 | SALES | | ADAMS | 1100.00 | RESEARCH | | JAMES | 950.00 | SALES | | FORD | 3000.00 | RESEARCH | | MILLER | 1300.00 | ACCOUNTING | ----------------------------- 14 rows in set (0.00 sec)-- 显示部门号为10的部门名员工名和工资 mysql select dept.deptno,dname,ename,sal from emp,dept where dept.deptnoemp.deptno and dept.deptno10; ------------------------------------- | deptno | dname | ename | sal | ------------------------------------- | 10 | ACCOUNTING | CLARK | 2450.00 | | 10 | ACCOUNTING | KING | 5000.00 | | 10 | ACCOUNTING | MILLER | 1300.00 | ------------------------------------- 3 rows in set (0.00 sec)-- 显示各个员工的姓名工资及工资级别mysql select ename,sal,grade,losal,hisal from salgrade,emp where emp.sal between losal and hisal; -------------------------------------- | ename | sal | grade | losal | hisal | -------------------------------------- | SMITH | 800.00 | 1 | 700 | 1200 | | ALLEN | 1600.00 | 3 | 1401 | 2000 | | WARD | 1250.00 | 2 | 1201 | 1400 | | JONES | 2975.00 | 4 | 2001 | 3000 | | MARTIN | 1250.00 | 2 | 1201 | 1400 | | BLAKE | 2850.00 | 4 | 2001 | 3000 | | CLARK | 2450.00 | 4 | 2001 | 3000 | | SCOTT | 3000.00 | 4 | 2001 | 3000 | | KING | 5000.00 | 5 | 3001 | 9999 | | TURNER | 1500.00 | 3 | 1401 | 2000 | | ADAMS | 1100.00 | 1 | 700 | 1200 | | JAMES | 950.00 | 1 | 700 | 1200 | | FORD | 3000.00 | 4 | 2001 | 3000 | | MILLER | 1300.00 | 2 | 1201 | 1400 | -------------------------------------- 14 rows in set (0.00 sec) 三、自连接 上述的笛卡尔积是两个不同的表进行的查询自连接是指在同一张表连接查询 案例 显示员工FORD的上级领导的编号和姓名mgr是员工领导的编号–empno 使用的子查询 mysql select ename,empno from emp where empno(select mgr from emp where enameFORD); --------------- | ename | empno | --------------- | JONES | 007566 | --------------- 1 row in set (0.00 sec) 使用多表查询自查询 mysql select t2.ename,t2.empno from emp as t1,emp as t2 where t1.enameFORD and t1.mgrt2.empno; --------------- | ename | empno | --------------- | JONES | 007566 | --------------- 1 row in set (0.00 sec) 四、子查询 子查询是指嵌入在其他sql语句中的select语句也叫嵌套查询 4.1 单行子查询 返回一行记录的子查询 显示SMITH同一部门的员工 mysql select * from emp where deptno(select deptno from emp where enameSMITH); -------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | -------------------------------------------------------------------------- | 007369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800.00 | NULL | 20 | | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 007876 | ADAMS | CLERK | 7788 | 1987-05-23 00:00:00 | 1100.00 | NULL | 20 | | 007902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | -------------------------------------------------------------------------- 5 rows in set (0.00 sec) 4.2 多行子查询 返回多行记录的子查询 in关键字 查询和10号部门的工作岗位相同的雇员的名字岗位工资部门号但是不包含10自己的 mysql select ename,job,sal,deptno from emp where job in(select distinct job from emp where deptno10) and deptno!10; --------------------------------- | ename | job | sal | deptno | --------------------------------- | JONES | MANAGER | 2975.00 | 20 | | BLAKE | MANAGER | 2850.00 | 30 | | SMITH | CLERK | 800.00 | 20 | | ADAMS | CLERK | 1100.00 | 20 | | JAMES | CLERK | 950.00 | 30 | --------------------------------- 5 rows in set (0.00 sec)查询和10号部门的工作岗位相同的雇员的名字岗位工资部门名字但是不包含10自己的 首先将上述的查询结构当做一张临时表再和dept表做笛卡尔积 mysql select ename,job,sal,dept.deptno,dname from(select ename,job,sal,deptno from emp where job in(select diistinct job from emp where deptno10) and deptno!10) as tmp,dept where tmp.deptnodept.deptno; ------------------------------------------- | ename | job | sal | deptno | dname | ------------------------------------------- | SMITH | CLERK | 800.00 | 20 | RESEARCH | | JONES | MANAGER | 2975.00 | 20 | RESEARCH | | ADAMS | CLERK | 1100.00 | 20 | RESEARCH | | BLAKE | MANAGER | 2850.00 | 30 | SALES | | JAMES | CLERK | 950.00 | 30 | SALES | ------------------------------------------- 5 rows in set (0.00 sec) all关键字: 显示工资比部门30的所有员工的工资高的员工的姓名、工资和部门号 mysql select * from emp where sal(select max(sal) from emp where deptno30); ---------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | ---------------------------------------------------------------------------- | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 007839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 007902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | ---------------------------------------------------------------------------- 4 rows in set (0.00 sec)mysql select * from emp where sal all(select distinct sal from emp where deptno30); ---------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | ---------------------------------------------------------------------------- | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 007839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 007902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | ---------------------------------------------------------------------------- 4 rows in set (0.00 sec) any关键字显示工资比部门30的任意员工的工资高的员工的姓名、工资和部门号包含自己部门的员工) mysql select * from emp where salany(select distinct sal from emp where deptno30 ); -------------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | -------------------------------------------------------------------------------- | 007499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600.00 | 300.00 | 30 | | 007521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250.00 | 500.00 | 30 | | 007566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 007654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 | 30 | | 007698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | NULL | 30 | | 007782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | NULL | 10 | | 007788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 007839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 007844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500.00 | 0.00 | 30 | | 007876 | ADAMS | CLERK | 7788 | 1987-05-23 00:00:00 | 1100.00 | NULL | 20 | | 007902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | | 007934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | NULL | 10 | -------------------------------------------------------------------------------- 12 rows in set (0.00 sec) 4.3 多列子查询 单行子查询是指子查询只返回单列单行数据 多行子查询是指返回单列多行数据都是针对单列而言的; 多列子查询则是指查询返回多个列数据的子查询语句 查询和SMITH的部门和岗位完全相同的所有雇员不含SMITH本人 mysql select * from emp where (deptno,job)(select deptno,job from emp where enameSMITH) and ename!SMITHH; ------------------------------------------------------------------------ | empno | ename | job | mgr | hiredate | sal | comm | deptno | ------------------------------------------------------------------------ | 007876 | ADAMS | CLERK | 7788 | 1987-05-23 00:00:00 | 1100.00 | NULL | 20 | ------------------------------------------------------------------------ 1 row in set (0.00 sec) 4.4 在from子句中使用子查询 子查询语句出现在from子句中。这里要用到数据查询的技巧把一个子查询当做一个临时表使用 显示每个高于【自己】部门平均工资的员工的姓名、部门、工资、平均工资 1.首先查出每个部门的平均工资并将查询结果当做临时表tmp 2.联合查询emp表与tmp表 mysql select emp.ename,emp.deptno,sal,avgsal from emp,(select deptno,avg(sal)avgsal from emp group by deptno) t1 where emp.depttnot1.deptno and emp.salt1.avgsal; ------------------------------------- | ename | deptno | sal | avgsal | ------------------------------------- | ALLEN | 30 | 1600.00 | 1566.666667 | | JONES | 20 | 2975.00 | 2175.000000 | | BLAKE | 30 | 2850.00 | 1566.666667 | | SCOTT | 20 | 3000.00 | 2175.000000 | | KING | 10 | 5000.00 | 2916.666667 | | FORD | 20 | 3000.00 | 2175.000000 | ------------------------------------- 6 rows in set (0.00 sec) 查找每个部门工资最高的人的姓名、工资、部门、最高工资 mysql select emp.ename,emp.sal,emp.deptno,t1.maxsal from(select deptno,max(sal)maxsal from emp group by deptno) t1,emp where emp.salt1.maxsal and emp.deptnot1.deptno; --------------------------------- | ename | sal | deptno | maxsal | --------------------------------- | BLAKE | 2850.00 | 30 | 2850.00 | | SCOTT | 3000.00 | 20 | 3000.00 | | KING | 5000.00 | 10 | 5000.00 | | FORD | 3000.00 | 20 | 3000.00 | --------------------------------- 4 rows in set (0.00 sec) 显示每个部门的信息部门名编号地址和人员数量 --多表 mysql select dept.dname,dept.deptno,dept.loc,count(*) 部门人数 from emp,dept where emp.deptnodept.deptno group by dept.deptno,dept.dname,dept.loc; -------------------------------------------- | dname | deptno | loc | 部门人数 | -------------------------------------------- | ACCOUNTING | 10 | NEW YORK | 3 | | RESEARCH | 20 | DALLAS | 5 | | SALES | 30 | CHICAGO | 6 | -------------------------------------------- 3 rows in set (0.00 sec) --子查询 mysql select dept.deptno,dname,cnt,loc from dept,(select count(*)cnt,deptno from emp group by deptno)tmp where dept.deptnotmp.deptno; ----------------------------------- | deptno | dname | cnt | loc | ----------------------------------- | 10 | ACCOUNTING | 3 | NEW YORK | | 20 | RESEARCH | 5 | DALLAS | | 30 | SALES | 6 | CHICAGO | ----------------------------------- 3 rows in set (0.00 sec) 4.5 合并查询 在实际应用中为了合并多个select的执行结果可以使用集合操作符 unionunion all 4.5.1 union union该操作符用于取得两个结果集的并集。当使用该操作符时会自动去掉结果集中的重复行 将工资大于2500或职位是MANAGER的人找出来 mysql select * from emp where sal2500 union select * from emp where jobMANAGER; --------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | --------------------------------------------------------------------------- | 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | NULL | 30 | | 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | NULL | 10 | --------------------------------------------------------------------------- 6 rows in set (0.00 sec) 4.5.2 union all union all该操作符用于取得两个结果集的并集。当使用该操作符时不会去掉结果集中的重复行。 mysql select * from emp where sal2500 union all select * from emp where jobMANAGER; --------------------------------------------------------------------------- | empno | ename | job | mgr | hiredate | sal | comm | deptno | --------------------------------------------------------------------------- | 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | NULL | 30 | | 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000.00 | NULL | 10 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | NULL | 20 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | NULL | 20 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | NULL | 10 | --------------------------------------------------------------------------- 8 rows in set (0.00 sec)五、实战OJ 查找所有员工入职时候的薪水情况 select s.emp_no,s.salary from salaries s,employees e where e.emp_nos.emp_no and e.hire_dates.from_date order by e.emp_no desc;获取所有非manager的员工emp_no select emp_no from employees where emp_no not in(select emp_no from dept_manager);
http://www.zqtcl.cn/news/739563/

相关文章:

  • ppt免费下载雷锋网站WordPress5分钟建站
  • 商店网站制作做签名照的网站
  • 自己制作一个网站广州自助网站制作
  • 个人网站吗wordpress超精简主题
  • 手机版免费申请微网站wordpress 跳转链接
  • 网站建设与管理好吗广州白云最新消息
  • 织梦动漫网站模版wordpress 页面文章列表
  • 东莞做网站沃德长沙市网站开发
  • 哪些网站做的最好厦门网站建设网站
  • 网站安全事件应急处置机制建设类似百度的网站
  • 内蒙古知名网站建设网站测速工具
  • 怎样建立网站赚钱怎么登录住建局官网
  • 建站自学网页转向功能网站
  • 网站都有什么费用做酒店网站有哪些目录
  • 本地郑州网站建设东莞网站优化中易
  • 动态域名可以建网站德州公司做网站
  • 深圳建设银行官方网站wordpress 添加qq
  • 甘肃第九建设集团公司网站网站对企业的好处
  • 论坛网站建设规划书公司网站建设与设计制作
  • 做棋牌游戏网站犯法吗如何进行搜索引擎的优化
  • 常见的网站首页布局有哪几种陈光锋网站运营推广新动向
  • 手机网站活动策划方案开一个设计公司
  • 宝塔建设网站教程visual studio 2010 网站开发教程
  • 做网站购买服务器做谷歌网站使用什么统计代码吗
  • 网站系统与网站源码的关系emlog轻松转wordpress
  • 网站的简介怎么在后台炒做吉林省住房城乡建设厅网站首页
  • 泉州易尔通网站建设国际酒店网站建设不好
  • 网页下载网站福田企业网站推广公司
  • 北京网站建设开发公司哪家好网站添加在线留言
  • 新建的网站怎么做seo优化平面广告创意设计