2021-03-02

select a.dept_name,a.`name`,a.dept_id, max(a.salary) from (select info.dept_id,info.dept_name,emp.name,emp.salary from tbl_department info,tbl_employee emp where info.dept_id = emp.dept_id

)a group by dept_id;

select a.dept_name,a.`name`, max(a.salary) from (select info.dept_id,info.dept_name,emp.name,emp.salary from tbl_department info,tbl_employee emp where info.dept_id = emp.dept_id

)a group by dept_id;

SELECT @@GLOBAL.sql_mode;

 set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

  select max(id) as id,name from tbl_employee group by name;

explain Select  distinct st.name from tbl_middle_student st left join tbl_middle_score sc on  st.id = sc.stu_id where sc.score = 100 order by st.name;

select name from tbl_middle_student where id in( select distinct(stu_id) from tbl_middle_score sc where sc.score = 100);

select name from tbl_middle_student st where EXISTS (select distinct(stu_id) as id from tbl_middle_score sc where sc.score = 100 and st.id = sc.stu_id);

select * from tbl_employee;

select * from tbl_department;

select a.dept_name,a.name, a.dept_id, max(a.salary) from (select info.dept_id,info.dept_name,emp.name,emp.salary from tbl_department info,tbl_employee emp where info.dept_id = emp.dept_id

)a group by dept_id;

select a.dept_name,a.`name`,a.dept_id, max(a.salary) from (select info.dept_id,info.dept_name,emp.name,emp.salary from tbl_department info,tbl_employee emp where info.dept_id = emp.dept_id

)a group by dept_id;

select a.dept_name,a.`name`, max(a.salary) from (select info.dept_id,info.dept_name,emp.name,emp.salary from tbl_department info,tbl_employee emp where info.dept_id = emp.dept_id

)a group by dept_id;

SELECT @@GLOBAL.sql_mode;

 set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

select dept_id,max(salary) from tbl_employee emp group by emp.dept_id;

select emp.dept_id,max(salary) as '薪资' from tbl_employee emp left join tbl_department depart on depart.dept_id = 

emp.dept_id

 group by emp.dept_id;


 select a.dept_name,emp.name, m.salary from (select emp.dept_id,max(salary) as 'salary' from tbl_employee emp left join tbl_department depart on depart.dept_id = 

emp.dept_id

 group by emp.dept_id) m right join tbl_department a on  a.dept_id = m.dept_id

left join tbl_employee emp on emp.salary = m.salary;


 select a.dept_name,emp.name, m.salary from (select info.dept_id,info.dept_name from tbl_department info)a


 select info.dept_id,info.dept_name,emp.name from tbl_department info,tbl_employee emp where info.dept_id = emp.dept_id



 select emp.name,max(salary) from tbl_employee emp left join tbl_department depart on depart.dept_id = 

emp.dept_id

 group by emp.dept_id;



 select emp.name,depart.dept_name,emp.dept_id, max(salary) from tbl_employee emp left join tbl_department depart on depart.dept_id = 

emp.dept_id

 group by emp.dept_id;


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一 介绍本节主题 多表连接查询复合条件连接查询子查询准备表 建表 create table department(...
    wujimozun阅读 221评论 0 0
  • @[TOC] 1.准备表 2. 多表连接查询 交叉连接:不适用任何匹配条件。生成笛卡尔积mysql> select...
    态度哥阅读 148评论 0 0
  • 查看当前所有存在的数据库 SHOW DATABASES; 创建测试数据库test_db CREATE DATABA...
    顶宝麻麻阅读 288评论 0 0
  • 一、SQL速成 结构查询语言(SQL)是用于查询关系数据库的标准语言,它包括若干关键字和一致的语法,便于数据库元件...
    shadow雨轩阅读 525评论 0 3
  • title: "Oracle创建表空间和表"date: 2021-02-01T20:17:20+08:00draf...
    大地缸阅读 256评论 0 0