码迷,mamicode.com
首页 > 其他好文 > 详细

表连接知识

时间:2021-04-13 12:40:20      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:val   where   desc   iss   sele   dep   char   group   evel   

#创建job_grades表
/*CREATE TABLE job_grades
(grade_level VARCHAR(3),
lowest_sal int,
highest_sal int);

INSERT INTO job_grades
VALUES (‘A‘, 1000, 2999);

INSERT INTO job_grades
VALUES (‘B‘, 3000, 5999);

INSERT INTO job_grades
VALUES(‘C‘, 6000, 9999);

INSERT INTO job_grades
VALUES(‘D‘, 10000, 14999);

INSERT INTO job_grades
VALUES(‘E‘, 15000, 24999);

INSERT INTO job_grades
VALUES(‘F‘, 25000, 40000);*/
#查询员工工资和工资级别
SELECT
salary,grade_level
FROM
employees e,job_grades j
WHERE
salary BETWEEN j.`lowest_sal`AND j.`highest_sal` ;


#查询有奖金的每个部门的部门名字和部门的领导编号和该部门的最低工资

SELECT
department_name,d.manager_id,MIN(salary)
FROM
departments d,employees e
WHERE
d.department_id=e.`department_id`
AND `commission_pct` IS NOT NULL
GROUP BY department_name,d.manager_id;


#查询每个工种的工种名和员工的个数,并且按员工个数降序
SELECT
COUNT(*),j.`job_title`
FROM
jobs j,employees e
WHERE
j.`job_id`=e.`job_id`
GROUP BY j.`job_title`
ORDER BY COUNT(*) DESC;

 

表连接知识

标签:val   where   desc   iss   sele   dep   char   group   evel   

原文地址:https://www.cnblogs.com/Dasnl/p/14651282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!