联邦航空管理局想知道您的每个飞行员(仅限员工,即EMP)有多少类型的飞机目前认证(符合资格)飞行。假设认证的有效期仅为一年。因此,列出每个目前有资格飞行的飞行员的飞行员和数量(date_certified)。请列出飞行员的全名,许可证编号和类型数量当前合格(认证)。 (提示:SYSDATE在MS Access中返回今天的日期,如date()。(SYSDATE +30)是从今天起的30天)。
这是飞行员表:
pilot_nbr, license_nbr, last_name, first_name, title, address, phone, office_nbr, contract_type, salary, manager_nbr
'701', '7111', 'Dark', 'Jack', '1st officer', '6 street', '6042233445', '789', 'PTE', '145000.00', NULL
'702', '7222', 'Mack', 'Bill', '1st officer', '7 street', '6043344556', '890', 'EMP', '155000.00', '701'
'703', '7333', 'Cheung', 'Charles', '2nd officer', '8 street', '6044455667', '503', 'PTE', '140000.00', '701'
'704', '7444', 'Gordon', 'Greg', '1st officer', '9 street', '6045566778', '123', 'EMP', '125000.00', '701'
'705', '7555', 'Basso', 'Nicki', '2nd officer', '5 street', '6046677889', '223', 'EMP', '163000.00', '701'
'706', '7666', 'Vettel', 'Sebast', '1st officer', '5 street', '6046677800', '523', 'EMP', '199000.00', '701'
'707', '7777', 'Hawke', 'Mike', '2nd officer', '7 street', '6046677326', '423', 'EMP', '139000.00', '701'
这是资格表:
pilot_nbr, plane_type, date_certified
'701', 'DE Prop', '2013-08-14'
'701', 'SE Prop', '2013-04-10'
'702', 'DE Prop', '2013-02-22'
'702', 'SE Jet', '2013-04-10'
'702', 'SE Prop', '2013-06-21'
'703', 'DE Prop', '2013-04-10'
'703', 'SE Jet', '2013-04-10'
'703', 'SE Prop', '2013-04-10'
'704', 'DE Prop', '2013-06-12'
'704', 'ME Jet', '2013-08-21'
'704', 'SE Jet', '2013-06-15'
'704', 'SE Prop', '2013-04-10'
这是我做的事情(不知道它是否正确)
SELECT first_name, last_name, license_nbr, Count(first_name) As 'No of types of airplane certified to fly'
FROM pilot, qualifies
WHERE pilot.pilot_nbr=qualifies.pilot_nbr AND contract_type='EMP' AND date_certified >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
GROUP BY first_name, last_name
我们将不胜感激。
答案 0 :(得分:0)
Hope this will solve your task...
SELECT p.first_name, p.last_name, p.license_nbr, Count(q.plane_type) As 'No of types of airplane certified to fly'
FROM pilot p inner join qualifies q on p.pilot_nbr = q.pilot_nbr
WHERE p.contract_type='EMP' AND DATE_SUB(q.date_certified, INTERVAL 1 YEAR) > CURDATE()
GROUP BY p.first_name, p.last_name, p.license_nbr;