您好,登錄后才能下訂單哦!
加篩選
#案例:有獎金的員工名和部門名
SELECT
last_name,department_name
FROM
employees AS e,departments AS d
WHERE
e.department_id=d.department_id
AND
e.commission_pct IS NOT NULL;
#案例:查詢城市名中第二個字符為o的部門名和城市名
SELECT
department_name,city
FROM
departments AS d,locations AS l
WHERE
d.location_id=l.location_id
AND
l.city LIKE'_o%';
加分組
#案例:查詢每個城市的部門個數
SELECT
COUNT(*),city
FROM
departments AS d,locations AS l
WHERE
d.`location_id`=l.`location_id`
GROUP BY
city;
#案例:查詢有獎金的每個部門的部門名和部門的領導編號和該部門的最低工資
SELECT
department_name,d.manager_id,MIN(salary)
FROM
employees AS e,departments AS d
WHERE
d.department_id=e.department_id
AND
commission_pct IS NOT NULL
GROUP BY
department_name,d.manager_id;
加排序
#案例:查詢每個工種的工種名和員工的個數,并且按員工個數降序
SELECT
job_title,COUNT(*)
FROM
employees AS e,jobs AS j
WHERE
e.job_id=j.job_id
GROUP BY
job_title
ORDER BY
COUNT(*) DESC;
三表連接
#案例:查詢員工名 、部門名、所在的城市
SELECT
last_name,department_name,city
FROM
employees AS e,departments AS d,locations AS l
WHERE
e.department_id=d.`department_id`
AND
d.`location_id`=l.location_id
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。