SELECT NAME,boyname
FROM beauty,boys
WHERE beauty.boyfriend_id=boys.id;
SELECT last_name,department_name
FROM employees,departments
WHERE employees.department_id=departments.department_id;
SELECT last_name,e.job_id,job_title
FROM employees e,jobs j
WHERE e.job_id=j.job_id;
SELECT last_name,department_name,commission_pct
FROM employees e,departments d
WHERE e. department_id=d.department_id
and e.commission_pct IS NOT NULL
SELECT department_name,city
FROM departments d,locations l
WHERE d.location_id=l.location_id
AND city LIKE "_o%";
SELECT COUNT(*) 个数,city
FROM departments d,locations l
WHERE d.location_id=l.location_id
GROUP BY city;
SELECT d.department_name,d.manager_id,MIN(salary)
FROM departments d,employees e
WHERE e.manager_id=d.manager_id
AND e.commission_pct IS NOT null
GROUP BY d.department_name,manager_id;
SELECT job_title,COUNT(*)
FROM employees e,jobs j
WHERE e.job_id=j.job_id
GROUP BY job_title
ORDER BY COUNT(*);
SELECT last_name,department_name,city
FROM departments d,employees e,locations l
WHERE e.department_id=d.department_id
AND d.location_id=l.location_id;
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 g
WHERE salary BETWEEN g.lowest_sal AND g.highest_sal;
SELECT e.last_name,e.manager_id,m.employee_id,m.last_name
FROM employees e,employees m
WHERE e.manager_id=m.employee_id;
seLECT last_name,department_name
FROM employees e
INNER JOIN departments d
ON e.department_id=d.department_id;
SELECT last_name,job_title
FROM employees e
INNER JOIN jobs j
ON e.job_id=j.job_id
WHERE e.last_name LIKE '%e%';
SELECT city ,COUNT(*) 部门个数
FROM departments d
INNER JOIN locations l
ON d.location_id=l.location_id
GROUP BY city
HAVING 部门个数>3;
SELECT COUNT(*) 个数,department_name
FROM employees e
INNER JOIN departments d
ON e.department_id=d.department_id
GROUP BY department_name
HAVING 个数>3
ORDER BY 个数 DESC;
SELECT salary,grade_level
FROM employees e
JOIN job_grades g
ON e.salary BETWEEN g.lowest_sal AND g.highest_sal;
SELECT e.last_name,e.manager_id,m.employee_id,m.last_name
FROM employees e
join employees m
on e.manager_id=m.employee_id
WHERE e.last_name LIKE '%k%';
SELECT b.name,bo.*
FROM beauty b
LEFT OUTER JOIN boys bo
ON b.boyfriend_id=bo.id
WHERE bo.id IS NULL;
USE girls
SELECT b.*,bo.*
FROM beauty b
CROSS JOIN boys bo;```