Write SQL code that returns the EMP_NUM and Number of ratings he/she earned (based on EARNEDRATING table, call this Num_RTG), for those who had at least got 1 rating earned, but the number of ratings he/she earned must lower than the average number of ratings for all employees who had earned ratings before, and such employee has been served as “Copilot” before.
SQL
SQL stands for Structured Query Language, is a form of communication that uses queries structured in a specific format to store, manage & retrieve data from a relational database.
Queries
A query is a type of computer programming language that is used to retrieve data from a database. Databases are useful in a variety of ways. They enable the retrieval of records or parts of records, as well as the performance of various calculations prior to displaying the results. A search query is one type of query that many people perform several times per day. A search query is executed every time you use a search engine to find something. When you press the Enter key, the keywords are sent to the search engine, where they are processed by an algorithm that retrieves related results from the search index. Your query's results are displayed on a search engine results page, or SER.
Write SQL code that returns the EMP_NUM and Number of ratings he/she earned (based on EARNEDRATING table, call this Num_RTG), for those who had at least got 1 rating earned, but the number of ratings he/she earned must lower than the average number of ratings for all employees who had earned ratings before, and such employee has been served as “Copilot” before.
![Table name: CHARTER
CHAR_TRIP CHAR_DATE AC_NUMBER CHAR_DESTINATION CHAR_DISTANCE CHAR_HOURS_FLOWN CHAR_HOURS_WAIT CHAR_FUEL_GALLONS CHAR_OL_QTS CUS_CODE Table name: EARNEDRATING
10001 05-Feb-16 2289
10002 05-Feb-16 2778V
10003 05-Feb-16 4278Y
10004 06-Feb-16 1484P
10005 06-Feb-16 2289
10006 06-Feb-16 4278Y
10007
06-Feb-16 2778V
07-Feb-16 1484P
10008
10009
07-Feb-16 2289L
10010
07-Feb-16 4278Y
10011
07-Feb-16 1484P
10012 08-Feb-16 2778V
08-Feb-16 4278Y
10013
10014
09-Feb-16 4278Y
10015 09-Feb-16 2289L
10016 09-Feb-16 2778V
10017 10-Feb-16 1484P
10018 10-Feb-16 4278Y
Table name: CREW
CHAR_TRIP EMP NUM CREW JOB
10001
104 P
10002
101 P
10003
105 P
10003
10004
10005
10006
10007
10007
10008
10009
10010
10011
10011
10012
10013
10014
10015
10015
10016
10016
10017
10018
10018
109 Copilot
106 Pilot
101 P
109 Pilot
104 P
105 Cop
106 Plot
105 Pilot
100 Plot
101 P
104 Cop
101 Po
105 P
106 Pilot
101 Cop
104 P
105 Cop
109 P
101 P
104 Copilot
105 Pilot
ATL
BNA
GNV
STL
ATL
STL
GNV
TYS
GNV
ATL
BNA
MOB
TYS
ATL
GNV
MOY
STL
TVS
10010 Ramas
10011 Dunne
10012 Smith
Table name: AIRCRAFT
AC_NUMBER MOD_CODE AC TTAF
1484P
PA23-250
2209L
C-90A
2778V
PA31-350
4278Y
PA31-350
10013 Clowski
10014 Orlando
10015 O'Brian
10016 Brown
10017 Williams
10018 Farriss
10019 Smith
106 Mrs.
107 Mr.
108 Mr.
109 Ms.
110 Mrs.
AC_TTEL AC_TTER
936
320
1574
472
1023
472
1574
644
1574
990
352
884
644
936
1645
312
508
644
1833.1 1833.1
4243.0
768.9
79929
2147.3
1513.1
622.1
Alfred
Leona
Kathy
Paul
Myron
Amy
James
George
Anne
Olette
101.8
1123.4
789.5
243.2
A
K
W
F
B
K
5.1
1.6
78
2.9
5.7
26
79
Table name: CUSTOMER
CUS_CODE CUS_LNAME CUS_FNAME CUS_INITIAL CUS_AREACODE CUS_PHONE CUS_BALANCE
844-2573
894-1238
894-2285
Table name: EMPLOYEE
EMP NUM EMP TITLE EMP LNAME EMP_FNAME EMP_INITIAL
100 Mr.
Kolmycz
Lewis
101 Ms.
102 Mr
Vandam
103 Ms.
Jones
104 Mr.
Lange
105 Mr.
Williams
Duzak
Diante
Wesenbach
Travis
Genkazi
George
Rhonda
Rhett
Anne
John
Robert
Jeanine
Jorge
Paul
Elizabeth
Leighia
6.6
6.2
1.9
3.9
6.1
6.7
15
3.1
3.8
615
713
615
615
615
713
615
615
713
615
D
0
M
P
D
K
D
R
K
W
22
0
0
Table name: PILOT
EMP_NUM PIL LICENSE
101 ATP
104 ATP
105 COM
106 COM
109 COM
4.9
3.5
5.2
0
0
23.4
3.2
5.3
42
4.5
2.1
0
0
0
4.5
894-2180
222-1672
442-3381
297-1228
290-2556
382-7185
297-3809
354.1
726
18-Jun-1961
19-May-1970
339.8
97.2
117.1
348.4
140.6
459.9
279.7
66.4
1
PL_RATINGS
ATP/SELMELAnstr/CFI
ATP/SELMELAnstr
COMM/SELMELA/CF
COMMISELMELAnstr
ATPISELMEL/SESAnstr/CF 1
1
2
2
215.1
174.3
302.6
459.5
672
105.5
167 A
0.00
0.00
896.54
1285.19
673.21
1014.56
0.00
0.00
0.00
453.98
EMP DOB
15-Jun-1942
19-Mar-1965
14-Nov-1958 20-Dec-1992
16-Oct-1974 28-Aug-2005
08-Nov-1971 20-Oct-1996
14-Mar-1975
12-Feb-1968
21-Aug-1974
14-Feb-1966
02-Ju-1996
18-Nov-1994
1
14-Apr-1991
01-Dec-1992
0
2
1
2
0
2
1
0
0
1
0
1
08-Jan-2006 PA31-350
05-Jan-1991
0
2
0
0
0
CFI
CFI
INSTR
MEL
SEL
SES
10011
10016 EMP_NUM RTG_CODE EARNRTO_DATE
10014
10019
10011
10017
10012
10014
10017
10016
10012
10010
10011
10017
10016
10011
10014
10017
EMP HIRE DATE
15-Mar-1987
25-Apr-1988 Table name: MODEL
Table name: RATING
RTG_CODE
RTO NAME
Certified Flight Instructor
Certified Flight Instructor, Instrument
Instrument
Mutiengine Land
PIL_MED_TYPE PIL_MED_DATE PL_PT135_DATE
20-Jan-16
18-Dec-15
05-Jan-16
10-Dec-15
22-Jan-16
101 CFI
101 CFI
101 INSTR
101 MEL
101 SEL
104 INSTR
104 MEL
104 SEL
105 CFI
105 INSTR
105 MEL
105 SEL
106 INSTR
106 MEL
106 SEL
109 CFI
109 CF
Single Engine, Land
Single Engine, Sea
109 INSTR
109 MEL
109 SEL
109 SES
11-Jan-16
17-Jan-16
02-Jan-16
02-Feb-16
15-Jan-16
MOD_CODE MOD_MANUFACTURER MOD_NAME MOD_SEATS MOD_CHO_MILE
C-90A Beechcraft
PA23-250 Piper
Piper
18-Feb-98
15-Dec-05
06-Nov-93
23-Jun-94
21-Apr-90
15-JM-96
29-Jan-97
12-Mar-95
18-Nov-97
17-Apr-95
12-Aug-95
23-Sep-94
KingAir
Aztec
Navajo Chieftain
20-Dec-95
02-Apr-96
10-Mar-94
05-Nov-90
21-Jun-03
23-4-96
15-Mar-97
05-Feb-96
12-May-96
8
6
10
2.67
1.93
2.35](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8f9fe09f-03d2-42c5-99ed-f24f20bfc31d%2Ff22b281d-065f-4c3b-b2ba-c8fd925c30b7%2F9rayqz_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)