MySQL初學筆記(第一次作業)

2020-10-14 19:00:41

查詢locations表中,所有的country_id(去重)

select DISTINCT country_id from locations;

選擇員工姓名的第三個字母是a的員工姓名和年薪

select last_name,salary*12 as 年薪
from employees
where last_name LIKE '__a%';

查詢employees表中,僱用時間在2004-02-06~2014-03-05之間的員工姓名與工號

select last_name,employee_id
from employees
where hiredate BETWEEN '2004-02-06' AND '2014-03-05';

擴充套件題:將上題條件改為在2004~2014之間

select last_name,employee_id
from employees
where year(hiredate) BETWEEN '2004' and '2014'

查詢locations表中,城市不在Roma、Tokyo、Seattle的城市和街道地址資訊,要求為城市起對應的中文別名

select city as 城市,street_address
from locations
where city not in('Roma','Tokyo','Seattle')

選擇公司中沒有管理者的員工姓名及job_id

select last_name,job_id
from employees
where manager_id is null

顯示出表employees表中first_name以’e’結尾的員工資訊

select *
from employees
where first_name like '%e'