EASY

Getting Started
How can I access the schemas, tables, and data used in the practice problems? Use livesql.oracle.com. All schemas and tables utilized in the current practice problem sets are readily available without the headache of software installation. Simply create an account and let the SQL mastering begin! For a subset of the problems, a script is required to be executed to create and subsequently populate the table referenced within the problem. Simply copy and paste the corresponding script provided in the Tables Requiring Script Execution section of the SQL PRACTICE PROBLEMS page.

Schema and Table Information
Information on the schemas, corresponding tables, and data used in the example problems can be found within the SQL PRACTICE PROBLEMS page. I recommend opening another browser window with this page pulled up for quick reference.

SELECT AND FROM CLAUSES

Problem 1
Retrieve all employee’s first names from the employees table.

Tables Required

hr.employees

Expected Output
first_name
Ellen
Sundar
Mozhe
David
Hermann
Shelli
Amit
Elizabeth
Sarah
David
Laura
Harrison
Alexis
Anthony
Gerald
Nanette
John
Kelly
Karen
Curtis
Lex
Julia
Jennifer
Louise
Bruce
Alberto
Britney
Daniel
Pat
Kevin
Jean
Tayler
Adam
Timothy
Ki
Girard
William
Douglas
Kimberely
Nancy
Danielle
Peter
Michael
Shelley
Guy
Alexander
Alyssa
Charles
Vance
Payam
Alexander
Janette
Steven
Neena
Sundita
Renske
James
David
Jack
Diana
Jason
Steven
James
Mattea
Randall
Susan
Samuel
Allan
Irene
Kevin
Julia
Donald
Christopher
TJ
Lisa
Karen
Valli
Joshua
Randall
Hazel
Luis
Trenna
Den
Michael
John
Nandita
Ismael
John
Sarath
Lindsey
William
Stephen
Martha
Patrick
Jonathon
Winston
Sigal
Peter
Oliver
Jose Manuel
Peter
Clara
Shanta
Alana
Matthew
Jennifer
Eleni
Solution
SELECT
    hr.employees.first_name
FROM
    hr.employees;

Problem 2
Retrieve the employee ID, hire date, and the job ID for each employee.

Tables Required

hr.employees

Expected Output
employee_idhire_datejob_id
10017-Jun-03AD_PRES
10121-Sep-05AD_VP
10213-Jan-01AD_VP
1033-Jan-06IT_PROG
10421-May-07IT_PROG
10525-Jun-05IT_PROG
1065-Feb-06IT_PROG
1077-Feb-07IT_PROG
10817-Aug-02FI_MGR
10916-Aug-02FI_ACCOUNT
11028-Sep-05FI_ACCOUNT
11130-Sep-05FI_ACCOUNT
1127-Mar-06FI_ACCOUNT
1137-Dec-07FI_ACCOUNT
1147-Dec-02PU_MAN
11518-May-03PU_CLERK
11624-Dec-05PU_CLERK
11724-Jul-05PU_CLERK
11815-Nov-06PU_CLERK
11910-Aug-07PU_CLERK
12018-Jul-04ST_MAN
12110-Apr-05ST_MAN
1221-May-03ST_MAN
12310-Oct-05ST_MAN
12416-Nov-07ST_MAN
12516-Jul-05ST_CLERK
12628-Sep-06ST_CLERK
12714-Jan-07ST_CLERK
1288-Mar-08ST_CLERK
12920-Aug-05ST_CLERK
13030-Oct-05ST_CLERK
13116-Feb-05ST_CLERK
13210-Apr-07ST_CLERK
13314-Jun-04ST_CLERK
13426-Aug-06ST_CLERK
13512-Dec-07ST_CLERK
1366-Feb-08ST_CLERK
13714-Jul-03ST_CLERK
13826-Oct-05ST_CLERK
13912-Feb-06ST_CLERK
1406-Apr-06ST_CLERK
14117-Oct-03ST_CLERK
14229-Jan-05ST_CLERK
14315-Mar-06ST_CLERK
1449-Jul-06ST_CLERK
1451-Oct-04SA_MAN
1465-Jan-05SA_MAN
14710-Mar-05SA_MAN
14815-Oct-07SA_MAN
14929-Jan-08SA_MAN
15030-Jan-05SA_REP
15124-Mar-05SA_REP
15220-Aug-05SA_REP
15330-Mar-06SA_REP
1549-Dec-06SA_REP
15523-Nov-07SA_REP
15630-Jan-04SA_REP
1574-Mar-04SA_REP
1581-Aug-04SA_REP
15910-Mar-05SA_REP
16015-Dec-05SA_REP
1613-Nov-06SA_REP
16211-Nov-05SA_REP
16319-Mar-07SA_REP
16424-Jan-08SA_REP
16523-Feb-08SA_REP
16624-Mar-08SA_REP
16721-Apr-08SA_REP
16811-Mar-05SA_REP
16923-Mar-06SA_REP
17024-Jan-06SA_REP
17123-Feb-07SA_REP
17224-Mar-07SA_REP
17321-Apr-08SA_REP
17411-May-04SA_REP
17519-Mar-05SA_REP
17624-Mar-06SA_REP
17723-Apr-06SA_REP
17824-May-07SA_REP
1794-Jan-08SA_REP
18024-Jan-06SH_CLERK
18123-Feb-06SH_CLERK
18221-Jun-07SH_CLERK
1833-Feb-08SH_CLERK
18427-Jan-04SH_CLERK
18520-Feb-05SH_CLERK
18624-Jun-06SH_CLERK
1877-Feb-07SH_CLERK
18814-Jun-05SH_CLERK
18913-Aug-05SH_CLERK
19011-Jul-06SH_CLERK
19119-Dec-07SH_CLERK
1924-Feb-04SH_CLERK
1933-Mar-05SH_CLERK
1941-Jul-06SH_CLERK
19517-Mar-07SH_CLERK
19624-Apr-06SH_CLERK
19723-May-06SH_CLERK
19821-Jun-07SH_CLERK
19913-Jan-08SH_CLERK
20017-Sep-03AD_ASST
20117-Feb-04MK_MAN
20217-Aug-05MK_REP
2037-Jun-02HR_REP
2047-Jun-02PR_REP
2057-Jun-02AC_MGR
2067-Jun-02AC_ACCOUNT
Solution
SELECT
    hr.employees.employee_id,
    hr.employees.hire_date,
    hr.employees.job_id
FROM
    hr.employees;

Problem 3
Retrieve the department ID, department name, manager ID, and location ID for each department.

Tables Required

hr.departments

Expected Output
department_iddepartment_namemanager_idlocation_id
10Administration2001700
20Marketing2011800
30Purchasing1141700
40Human Resources2032400
50Shipping1211500
60IT1031400
70Public Relations2042700
80Sales1452500
90Executive1001700
100Finance1081700
110Accounting2051700
120Treasury1700
130Corporate Tax1700
140Control And Credit1700
150Shareholder Services1700
160Benefits1700
170Manufacturing1700
180Construction1700
190Contracting1700
200Operations1700
210IT Support1700
220NOC1700
230IT Helpdesk1700
240Government Sales1700
250Retail Sales1700
260Recruiting1700
270Payroll1700
Solution
SELECT
    hr.departments.department_id,
    hr.departments.department_name,
    hr.departments.manager_id,
    hr.departments.location_id
FROM
    hr.departments;

Problem 4
Retrieve all employee IDs. Rename this column to read as “worker_id.”

Tables Required

hr.employees

Expected Output
worker_id
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
Solution
SELECT
    hr.employees.employee_id AS worker_id
FROM
    hr.employees;

Problem 5
For each job, retrieve the job code, job title, minimum salary, and maximum salary. Rename these columns to read as job_code, title, minimum_salary, and maximum_salary, respectively.

Tables Required

hr.jobs

Expected Output
job_codetitleminimum_salarymaximum_salary
AD_PRESPresident2008040000
AD_VPAdministration Vice President1500030000
AD_ASSTAdministration Assistant30006000
FI_MGRFinance Manager820016000
FI_ACCOUNTAccountant42009000
AC_MGRAccounting Manager820016000
AC_ACCOUNTPublic Accountant42009000
SA_MANSales Manager1000020080
SA_REPSales Representative600012008
PU_MANPurchasing Manager800015000
PU_CLERKPurchasing Clerk25005500
ST_MANStock Manager55008500
ST_CLERKStock Clerk20085000
SH_CLERKShipping Clerk25005500
IT_PROGProgrammer400010000
MK_MANMarketing Manager900015000
MK_REPMarketing Representative40009000
HR_REPHuman Resources Representative40009000
PR_REPPublic Relations Representative450010500
Solution
SELECT
    hr.jobs.job_id AS job_code,
    hr.jobs.job_title AS title,
    hr.jobs.min_salary AS minimum_salary,
    hr.jobs.max_salary AS maximum_salary
FROM
    hr.jobs;

Problem 6
Retrieve the job ID, job title, maximum salary, minimum salary, and salary range for each job. Salary range is defined as the difference between the maximum salary and minimum salary. Alias the difference as “salary_range.”

Tables Required

hr.jobs

Expected Output
job_idjob_titlemax_salarymin_salarysalary_range
AD_PRESPresident400002008019920
AD_VPAdministration Vice President300001500015000
AD_ASSTAdministration Assistant600030003000
FI_MGRFinance Manager1600082007800
FI_ACCOUNTAccountant900042004800
AC_MGRAccounting Manager1600082007800
AC_ACCOUNTPublic Accountant900042004800
SA_MANSales Manager200801000010080
SA_REPSales Representative1200860006008
PU_MANPurchasing Manager1500080007000
PU_CLERKPurchasing Clerk550025003000
ST_MANStock Manager850055003000
ST_CLERKStock Clerk500020082992
SH_CLERKShipping Clerk550025003000
IT_PROGProgrammer1000040006000
MK_MANMarketing Manager1500090006000
MK_REPMarketing Representative900040005000
HR_REPHuman Resources Representative900040005000
PR_REPPublic Relations Representative1050045006000
Solution
SELECT
    hr.jobs.job_id,
    hr.jobs.job_title,
    hr.jobs.max_salary,
    hr.jobs.min_salary,
    hr.jobs.max_salary - hr.jobs.min_salary AS salary_range
FROM
    hr.jobs;

Problem 7
Retrieve the country id and country name for each country.

Tables Required

hr.countries

Expected Output
country_idcountry_name
ARArgentina
AUAustralia
BEBelgium
BRBrazil
CACanada
CHSwitzerland
CNChina
DEGermany
DKDenmark
EGEgypt
FRFrance
ILIsrael
INIndia
ITItaly
JPJapan
KWKuwait
MLMalaysia
MXMexico
NGNigeria
NLNetherlands
SGSingapore
UKUnited Kingdom
USUnited States of America
ZMZambia
ZWZimbabwe
Solution
SELECT
    hr.countries.country_id,
    hr.countries.country_name
FROM
    hr.countries;

Problem 8
Retrieve the employee ID, email, and phone number for each employee.

Tables Required

hr.employees

Expected Output
employee_idemailphone_number
100SKING515.123.4567
101NKOCHHAR515.123.4568
102LDEHAAN515.123.4569
103AHUNOLD590.423.4567
104BERNST590.423.4568
105DAUSTIN590.423.4569
106VPATABAL590.423.4560
107DLORENTZ590.423.5567
108NGREENBE515.124.4569
109DFAVIET515.124.4169
110JCHEN515.124.4269
111ISCIARRA515.124.4369
112JMURMAN515.124.4469
113LPOPP515.124.4567
114DRAPHEAL515.127.4561
115AKHOO515.127.4562
116SBAIDA515.127.4563
117STOBIAS515.127.4564
118GHIMURO515.127.4565
119KCOLMENA515.127.4566
120MWEISS650.123.1234
121AFRIPP650.123.2234
122PKAUFLIN650.123.3234
123SVOLLMAN650.123.4234
124KMOURGOS650.123.5234
125JNAYER650.124.1214
126IMIKKILI650.124.1224
127JLANDRY650.124.1334
128SMARKLE650.124.1434
129LBISSOT650.124.5234
130MATKINSO650.124.6234
131JAMRLOW650.124.7234
132TJOLSON650.124.8234
133JMALLIN650.127.1934
134MROGERS650.127.1834
135KGEE650.127.1734
136HPHILTAN650.127.1634
137RLADWIG650.121.1234
138SSTILES650.121.2034
139JSEO650.121.2019
140JPATEL650.121.1834
141TRAJS650.121.8009
142CDAVIES650.121.2994
143RMATOS650.121.2874
144PVARGAS650.121.2004
145JRUSSEL011.44.1344.429268
146KPARTNER011.44.1344.467268
147AERRAZUR011.44.1344.429278
148GCAMBRAU011.44.1344.619268
149EZLOTKEY011.44.1344.429018
150PTUCKER011.44.1344.129268
151DBERNSTE011.44.1344.345268
152PHALL011.44.1344.478968
153COLSEN011.44.1344.498718
154NCAMBRAU011.44.1344.987668
155OTUVAULT011.44.1344.486508
156JKING011.44.1345.429268
157PSULLY011.44.1345.929268
158AMCEWEN011.44.1345.829268
159LSMITH011.44.1345.729268
160LDORAN011.44.1345.629268
161SSEWALL011.44.1345.529268
162CVISHNEY011.44.1346.129268
163DGREENE011.44.1346.229268
164MMARVINS011.44.1346.329268
165DLEE011.44.1346.529268
166SANDE011.44.1346.629268
167ABANDA011.44.1346.729268
168LOZER011.44.1343.929268
169HBLOOM011.44.1343.829268
170TFOX011.44.1343.729268
171WSMITH011.44.1343.629268
172EBATES011.44.1343.529268
173SKUMAR011.44.1343.329268
174EABEL011.44.1644.429267
175AHUTTON011.44.1644.429266
176JTAYLOR011.44.1644.429265
177JLIVINGS011.44.1644.429264
178KGRANT011.44.1644.429263
179CJOHNSON011.44.1644.429262
180WTAYLOR650.507.9876
181JFLEAUR650.507.9877
182MSULLIVA650.507.9878
183GGEONI650.507.9879
184NSARCHAN650.509.1876
185ABULL650.509.2876
186JDELLING650.509.3876
187ACABRIO650.509.4876
188KCHUNG650.505.1876
189JDILLY650.505.2876
190TGATES650.505.3876
191RPERKINS650.505.4876
192SBELL650.501.1876
193BEVERETT650.501.2876
194SMCCAIN650.501.3876
195VJONES650.501.4876
196AWALSH650.507.9811
197KFEENEY650.507.9822
198DOCONNEL650.507.9833
199DGRANT650.507.9844
200JWHALEN515.123.4444
201MHARTSTE515.123.5555
202PFAY603.123.6666
203SMAVRIS515.123.7777
204HBAER515.123.8888
205SHIGGINS515.123.8080
206WGIETZ515.123.8181
Solution
SELECT
    hr.employees.employee_id,
    hr.employees.email,
    hr.employees.phone_number
FROM
    hr.employees;

Problem 9
Retrieve the job ID, job title, and minimum salary for each job at the company.

Tables Required

hr.jobs

Expected Output
job_idjob_titlemin_salary
AD_PRESPresident20080
AD_VPAdministration Vice President15000
AD_ASSTAdministration Assistant3000
FI_MGRFinance Manager8200
FI_ACCOUNTAccountant4200
AC_MGRAccounting Manager8200
AC_ACCOUNTPublic Accountant4200
SA_MANSales Manager10000
SA_REPSales Representative6000
PU_MANPurchasing Manager8000
PU_CLERKPurchasing Clerk2500
ST_MANStock Manager5500
ST_CLERKStock Clerk2008
SH_CLERKShipping Clerk2500
IT_PROGProgrammer4000
MK_MANMarketing Manager9000
MK_REPMarketing Representative4000
HR_REPHuman Resources Representative4000
PR_REPPublic Relations Representative4500
Solution
SELECT
    hr.jobs.job_id,
    hr.jobs.job_title,
    hr.jobs.min_salary
FROM
    hr.jobs;

Problem 10
Retrieve the location ID, city, and state/province for all warehouse/department locations.

Tables Required

hr.locations

Expected Output
location_idcitystate_province
1000Roma
1100Venice
1200TokyoTokyo Prefecture
1300Hiroshima
1400SouthlakeTexas
1500South San FranciscoCalifornia
1600South BrunswickNew Jersey
1700SeattleWashington
1800TorontoOntario
1900WhitehorseYukon
2000Beijing
2100BombayMaharashtra
2200SydneyNew South Wales
2300Singapore
2400London
2500OxfordOxford
2600StretfordManchester
2700MunichBavaria
2800Sao PauloSao Paulo
2900GenevaGeneve
3000BernBE
3100UtrechtUtrecht
3200Mexico CityDistrito Federal,
Solution
SELECT
    hr.locations.location_id,
    hr.locations.city,
    hr.locations.state_province
FROM
    hr.locations;

WHERE CLAUSE WITH COMPARISON OPERATORS

Problem 11
Retrieve the location ID, street address, city, and state/province for departments or warehouses located in Texas.
Solution

SELECT
    hr.locations.location_id,
    hr.locations.street_address,
    hr.locations.city,
    hr.locations.state_province
FROM
    hr.locations
WHERE
    hr.locations.state_province = 'Texas';

Problem 12
Retrieve the employee ID, job ID, and hire date for employees hired in year 2007 or later.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.hire_date
FROM
    hr.employees
WHERE
    hr.employees.hire_date >= '01-JAN-07';

Problem 13
Retrieve the department ID, department name, and location ID for departments/warehouses with location IDs other than 1700.
Solution

SELECT
    hr.departments.department_id,
    hr.departments.department_name,
    hr.departments.location_id
FROM
    hr.departments
WHERE
    hr.departments.location_id != 1700;

Problem 14
Retrieve the employee ID, first name, last name, and job ID for each programmer (i.e., those employees with a job ID of “IT_PROG.”
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.first_name,
    hr.employees.last_name,
    hr.employees.job_id
FROM
    hr.employees
WHERE
    hr.employees.job_id = 'IT_PROG';

Problem 15
Retrieve the location ID, city, and state/province, and country ID for department/warehouse locations outside of the United States.
Solution

SELECT
    hr.locations.location_id,
    hr.locations.city,
    hr.locations.state_province,
    hr.locations.country_id
FROM
    hr.locations
WHERE
    hr.locations.country_id != 'US';

Problem 16
Retrieve the employee ID, job ID, and salary for employees with a salary of greater than or equal to $10,000.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.salary >= 10000;

WHERE CLAUSE WITH IN, NOT IN, AND BETWEEN LOGICAL OPERATORS

Problem 17
Retrieve the location ID, city, state/province, and country ID for department/warehouse locations in the United States or Canada.
Solution

SELECT
    hr.locations.location_id,
    hr.locations.city,
    hr.locations.state_province,
    hr.locations.country_id
FROM
    hr.locations
WHERE
    hr.locations.country_id IN ('US', 'CA');

Problem 18
Retrieve the location ID, city, state/province, and country ID for department/warehouse locations outside the United States and Canada.
Solution

SELECT
    hr.locations.location_id,
    hr.locations.city,
    hr.locations.state_province,
    hr.locations.country_id
FROM
    hr.locations
WHERE
    hr.locations.country_id NOT IN ('US', 'CA');

Problem 19
Retrieve the employee ID and salary for all associates with a salary between $6,000 and $10,000, inclusive.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.salary BETWEEN 6000 AND 10000;

Problem 20
Retrieve the employee ID, first name, last name, job ID, hire date, and salary for all employees hired between 2004 and 2006, inclusive.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.first_name,
    hr.employees.last_name,
    hr.employees.job_id,
    hr.employees.hire_date,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.hire_date BETWEEN '01-JAN-04' AND '31-DEC-06';

Problem 21
Retrieve the employee ID, job ID, and salary for employees with job IDs other than IT_PROG, SA_MAN, and PU_CLERK.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.job_id NOT IN ('IT_PROG', 'SA_MAN', 'PU_CLERK');

Problem 22
Retrieve the employee ID, job ID, hire date, and salary for employees with salaries between $15,000 and $30,000, inclusive.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.hire_date,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.salary BETWEEN 15000 AND 30000;

WHERE CLAUSE WITH LIKE AND NOT LIKE LOGICAL OPERATORS

Problem 23
Retrieve the employee ID and first names of employees with a first name starting with the letter ‘A.’
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.first_name
FROM
    hr.employees
WHERE
    hr.employees.first_name LIKE 'A%';

Problem 24
Retrieve the employee ID and first names of employees with a first name starting with the letter ‘C’ followed by any sequence of characters and ending with the letter ‘s.’
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.first_name
FROM
    hr.employees
WHERE
    hr.employees.first_name LIKE 'C%s';

Problem 25
Retrieve employee phone numbers where the first digit is a 5, 3rd to last digit is a 1, second to last digit is any number, and the final digit is a 9.
Solution

SELECT
    hr.employees.phone_number
FROM
    hr.employees
WHERE
    hr.employees.phone_number LIKE '5%1_9';

Problem 26
Retrieve the employee ID and last name of employees with a last name not starting with the letter ‘B.’
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.last_name
FROM
    hr.employees
WHERE
    hr.employees.last_name NOT LIKE 'B%';

Problem 27
Retrieve all employee IDs for employees with a phone number containing the sequence of digits, 423.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.phone_number
FROM
    hr.employees
WHERE
    hr.employees.phone_number LIKE '%423%';

Problem 28
Retrieve the employee ID and job ID for those employees with job IDs starting with the letters ‘AD.’
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id
FROM
    hr.employees
WHERE
    hr.employees.job_id LIKE 'AD%';

Problem 29
Retrieve the employee ID and salary for employees with a salary starting with the 1 digit followed by a single digit of any value and ending with 3 zeros (e.g., 14000).
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.salary LIKE '1_000';

Problem 30
Retrieve the country ID and country name for country names starting with ‘A’ and ending in ‘a.’
Solution

SELECT
    hr.countries.country_id,
    hr.countries.country_name
FROM
    hr.countries
WHERE
    hr.countries.country_name LIKE 'A%a';

Problem 31
Retrieve the employee ID and phone number of employees where the phone number doesn’t begin with ‘650.’
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.phone_number
FROM
    hr.employees
WHERE
    hr.employees.phone_number NOT LIKE '650%';

WHERE CLAUSE WITH IS NULL AND IS NOT NULL

Problem 32
Retrieve the department ID, department name, and manager ID for departments without a manager ID assigned.
Solution

SELECT
    hr.departments.department_id,
    hr.departments.department_name,
    hr.departments.manager_id
FROM
    hr.departments
WHERE
    hr.departments.manager_id IS NULL;

Problem 33
Retrieve the department ID, department name, and manager ID for departments with a manager ID assigned.
Solution

SELECT
    hr.departments.department_id,
    hr.departments.department_name,
    hr.departments.manager_id
FROM
    hr.departments
WHERE
    hr.departments.manager_id IS NOT NULL;

Problem 34
Retrieve the employee ID and commission percentage for those employees with existing commission percentages
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.commission_pct
FROM
    hr.employees
WHERE
    hr.employees.commission_pct IS NOT NULL;

Problem 35
Retrieve the employee ID and commission percentage for those employees with non-existing commission percentages.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.commission_pct
FROM
    hr.employees
WHERE
    hr.employees.commission_pct IS NULL;

WHERE CLAUSE WITH MULTIPLE AND AND/OR LOGICAL OPERATORS

Problem 36
Retrieve the employee ID, job ID, salary, and manager ID for all employees with a manager ID of 100 or 108 and a salary greater than $12,000.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.salary,
    hr.employees.manager_id
FROM
    hr.employees
WHERE
    hr.employees.manager_id IN (100, 108)
    AND hr.employees.salary > 12000;

Problem 37
Retrieve the job ID, job title, minimum salary, and maximum salary for management jobs or those jobs with a minimum salary greater than 20,000 and a maximum salary greater than 25,000.
Solution

SELECT
    hr.jobs.job_id,
    hr.jobs.job_title,
    hr.jobs.min_salary,
    hr.jobs.max_salary
FROM
    hr.jobs
WHERE
    hr.jobs.job_title LIKE '%Manager'
    OR (hr.jobs.min_salary > 20000
        AND hr.jobs.max_salary > 25000);

Problem 38
Retrieve the employee ID, job ID, and department ID employees for employees that meet one or more of the following conditions:
Department ID is equal to 90 and the job ID is equal to ‘AD_PRES’
Department ID is equal to 100 and the job ID is equal to ‘FI_ACCOUNT’
Employee ID is equal to 115
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.department_id
FROM
    hr.employees
WHERE
    (hr.employees.department_id = 90
    	AND hr.employees.job_id = 'AD_PRES')
    OR (hr.employees.department_id = 100
    	AND hr.employees.job_id = 'FI_ACCOUNT')
    OR hr.employees.employee_id = '115';

Problem 39
Retrieve the employee ID, hire date, job ID, and salary for employees hired on as programmers in year 2007.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.hire_date,
    hr.employees.job_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    hr.employees.hire_date >= '01-JAN-07'
    AND hr.employees.hire_date < '01-JAN-08'
    AND hr.employees.job_id = 'IT_PROG';

Problem 40
Retrieve the employee ID, hire date, job ID, and salary for employees that were hired on as programmers or in the year 2007.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.hire_date,
    hr.employees.job_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    (hr.employees.hire_date >= '01-JAN-07'
    	AND hr.employees.hire_date < '01-JAN-08')
    OR hr.employees.job_id = 'IT_PROG';

Problem 41
Retrieve the employee ID, hire date, job ID, and salary for employees that were hired in year 2007 or were hired on as programmers with a salary greater than 5000.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.hire_date,
    hr.employees.job_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    (hr.employees.hire_date >= '01-JAN-07'
    	AND hr.employees.hire_date < '01-JAN-08')
    OR (hr.employees.job_id = 'IT_PROG'
    	AND hr.employees.salary > 5000);

Problem 42
Retrieve the employee ID, hire date, job ID, manager ID, and salary for employees that were hired in year 2007 or were hired on as programmers with a salary greater than 5000 or employees without a manager ID assigned and with a salary greater than 5000.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.hire_date,
    hr.employees.job_id,
    hr.employees.manager_id,
    hr.employees.salary
FROM
    hr.employees
WHERE
    (hr.employees.hire_date >= '01-JAN-07'
    	AND hr.employees.hire_date < '01-JAN-08')
    OR ((hr.employees.job_id = 'IT_PROG'
    	OR hr.employees.manager_id IS NULL)
    	AND hr.employees.salary > 5000);

GROUP BY CLAUSE AND COMPUTING AGGREGATES

Problem 43
Retrieve the minimum salary, maximum salary, average salary, and total sum of salaries. Provide appropriate aliases for the aggregations.
Solution

SELECT
    MIN(hr.employees.salary) AS minimum_salary,
    MAX(hr.employees.salary) AS maximum_salary,
    AVG(hr.employees.salary) AS average_salary,
    SUM(hr.employees.salary) AS salary_summation
FROM
    hr.employees;

Problem 44
For each job ID, compute the average employee salary with respect to the job ID. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.employees.job_id,
    AVG(hr.employees.salary) AS average_salary
FROM
    hr.employees
GROUP BY
    hr.employees.job_id;

Problem 45
For each job ID, compute the minimum and maximum salary with respect to the job ID. Provide appropriate aliases for the aggregations.
Solution

SELECT
    hr.employees.job_id,
    MIN(hr.employees.salary) AS minimum_salary,
    MAX(hr.employees.salary) AS maximum_salary
FROM
    hr.employees
GROUP BY
    hr.employees.job_id;

Problem 46
For each existing job ID and manager ID combination, compute the number of employees and the average salary for those employees. Provide appropriate aliases for the aggregations.
Solution

SELECT
    hr.employees.job_id,
    hr.employees.manager_id,
    COUNT(hr.employees.salary) AS employee_count,
    AVG(hr.employees.salary) AS average_salary
FROM
    hr.employees
GROUP BY
    hr.employees.job_id,
    hr.employees.manager_id;

Problem 47
For each region ID, compute the number of countries assigned the region ID. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.countries.region_id,
    COUNT(hr.countries.region_id) AS country_count
FROM
    hr.countries
GROUP BY
    hr.countries.region_id;

Problem 48
For each manager ID, compute the number of employees assigned the manager ID. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.employees.manager_id,
    COUNT(hr.employees.employee_id) AS employee_count
FROM
    hr.employees
GROUP BY
    hr.employees.manager_id;

Problem 49
For each manager ID, compute the maximum salary for employees assigned the manager ID. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.employees.manager_id,
    MAX(hr.employees.salary) AS maximum_salary
FROM
    hr.employees
GROUP BY
    hr.employees.manager_id;

Problem 50
For each country ID and state/province combination, compute the number of department/warehouse locations. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.locations.country_id,
    hr.locations.state_province,
    COUNT(hr.locations.state_province) AS warehouse_count
FROM
    hr.locations
GROUP BY
    hr.locations.country_id,
    hr.locations.state_province;

HAVING CLAUSE

Problem 51
For each job ID, compute the minimum and maximum salary with respect to the job ID. Return only job IDs with an range (MAX Salary – MIN Salary for each job ID) of salaries greater than or equal to $3,000. Provide appropriate aliases for the aggregations.
Solution

SELECT
    hr.employees.job_id,
    MIN(hr.employees.salary) AS minimum_salary,
    MAX(hr.employees.salary) AS maximum_salary
FROM
    hr.employees
GROUP BY
    hr.employees.job_id
HAVING
    MAX(hr.employees.salary) - MIN(hr.employees.salary) >= 3000;

Problem 52
For each existing job ID and manager ID combination, compute the number of employees and the average salary for those employees. Return only those job ID and manager ID combinations for which at least two employees are employed under the respective job ID and manager ID combination. Provide appropriate aliases for the aggregations.
Solution

SELECT
    hr.employees.job_id,
    hr.employees.manager_id,
    COUNT(hr.employees.salary) AS employee_count,
    AVG(hr.employees.salary) AS average_salary
FROM
    hr.employees
GROUP BY
    hr.employees.job_id,
    hr.employees.manager_id
HAVING
    COUNT(hr.employees.salary) > 1;

Problem 53
Retrieve the department ID(s) and the sum of the employees’ salaries for each department ID for departments with a total salary of greater than $100,000. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.employees.department_id,
    SUM(hr.employees.salary) AS total_salary
FROM
    hr.employees
GROUP BY
    hr.employees.department_id
HAVING
    SUM(hr.employees.salary) > 100000;

Problem 54
Retrieve the department IDs and the number of employees where more than 5 employees are assigned/work in. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.employees.department_id,
    COUNT(hr.employees.employee_id) AS employee_count
FROM
    hr.employees
GROUP BY
    hr.employees.department_id
HAVING
    COUNT(hr.employees.employee_id) > 5;

Problem 55
Retrieve the employee ID(s) and number of jobs each employee has held for employees that have held more than 2 jobs. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.job_history.employee_id,
    COUNT(*) AS job_count
FROM
    hr.job_history
GROUP BY
    hr.job_history.employee_id
HAVING
    COUNT(*) > 1;

ORDER BY CLAUSE

Problem 56
Retrieve employee IDs, job IDs, hire dates, and salaries for all employees. Sort/order the result set by hire date in ascending order and by salary in descending order.
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.hire_date,
    hr.employees.salary
FROM
    hr.employees
ORDER BY
    hr.employees.hire_date,
    hr.employees.salary DESC

Problem 57
Retrieve country IDs, country names, and region IDs for all countries. Sort/order the result set by region ID in ascending order and by country name in ascending order.
Solution

SELECT
    hr.countries.country_id,
    hr.countries.country_name,
    hr.countries.region_id
FROM
    hr.countries
ORDER BY
    hr.countries.region_id,
    hr.countries.country_name;

Problem 58
Retrieve the employee ID and hire date for each employee. Sort/order the result set by hire date in ascending order (i.e., oldest to newest).
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.hire_date
FROM
    hr.employees
ORDER BY
    hr.employees.hire_date;

Problem 59
Retrieve the employee ID, job ID, and salary for each employee. Sort/order the result set by salary in descending order (i.e., largest salary to smallest salary).
Solution

SELECT
    hr.employees.employee_id,
    hr.employees.job_id,
    hr.employees.salary
FROM
    hr.employees
ORDER BY
    hr.employees.salary DESC;

Problem 60
Retrieve the manager ID, employee ID, and salary for each employee. Sort/order the result set by manager ID (ascending) and within each manager, sort employee salaries in descending order.
Solution

SELECT
    hr.employees.manager_id,
    hr.employees.employee_id,
    hr.employees.salary
FROM
    hr.employees
ORDER BY
    hr.employees.manager_id,
    hr.employees.salary DESC;

Problem 61
For each country ID, return the number of departments/warehouses. Sort/order the result set by the number of departments/warehouses located in each country. Provide an appropriate alias for the aggregation.
Solution

SELECT
    hr.locations.country_id,
    COUNT(hr.locations.country_id) AS warehouse_count
FROM
    hr.locations
GROUP BY
    hr.locations.country_id
ORDER BY
    warehouse_count DESC;

ASSORTED PROBLEMS

Problem 62
Write a query that returns a result set containing, for each product, the product ID, product name, product description, list price, and minimum price. In addition, include a derived column containing the difference between the listing price and the minimum price. Alias this column as “amount_above_min.”
Solution

SELECT
	oe.product_information.product_id,
	oe.product_information.product_name,
	oe.product_information.product_description,
	oe.product_information.list_price,
	oe.product_information.min_price,
	oe.product_information.list_price - oe.product_information.min_price AS amount_above_min
FROM
	oe.product_information;

Problem 63
Write a query that returns a result set containing, for each customer, the customer ID, customer first name, customer last name, and credit limit. Only include customers with a last name starting with ‘A’ that also have a credit limit less than or equal to 1200. Sort the result set by credit limit, ascending.
Solution

SELECT
	oe.customers.customer_id,
	oe.customers.cust_first_name,
	oe.customers.cust_last_name,
	oe.customers.credit_limit
FROM
	oe.customers
WHERE
	oe.customers.cust_last_name LIKE 'A%'
	AND oe.customers.credit_limit <= 1200
ORDER BY
	oe.customers.credit_limit;

Problem 64
Write a query that returns a result set containing, for each order, the order ID, order date, and order total. Only include orders placed in year 2008 and later with an order total greater than $50,000 or for those orders placed in year 2007 with an order total greater than $25,000. Sort the result set by order date (ascending) and by order total (descending).
Solution

SELECT
	oe.orders.order_id,
	oe.orders.order_date,
	oe.orders.order_total
FROM
	oe.orders
WHERE
	(oe.orders.order_date >= '01-JAN-08'
		AND oe.orders.order_total > 50000)
	OR (oe.orders.order_date BETWEEN '01-JAN-07' AND '31-DEC-07'
		AND oe.orders.order_total > 25000)
ORDER BY
	oe.orders.order_date,
	oe.orders.order_total DESC;

Problem 65
Write a query that returns a result set containing the number of customers for each gender and credit limit combination. Gender and credit limit data should be included in the result set. Sort the result set by credit limit (ascending) and gender (ascending).
Solution

SELECT
	oe.customers.gender,
	oe.customers.credit_limit,
	COUNT(oe.customers.gender)
FROM
	oe.customers
GROUP BY
	oe.customers.gender,
	oe.customers.credit_limit
ORDER BY
	oe.customers.credit_limit,
	oe.customers.gender;

Problem 66
Write a query that returns a result set containing the number of customers for each natural language support territory (nls_territory), gender, and credit limit combination. NLS territory, gender, and credit limit data should be included in the result set. Only include those combinations for which a single customer is aligned/belongs. Sort the result set by NLS territory (ascending), credit limit (ascending), and gender (ascending).
Solution

SELECT
	oe.customers.nls_territory,
	oe.customers.gender,
	oe.customers.credit_limit,
	COUNT(*)
FROM
	oe.customers
GROUP BY
	oe.customers.nls_territory,
	oe.customers.gender,
	oe.customers.credit_limit
HAVING
	COUNT(*) = 1
ORDER BY
	oe.customers.nls_territory,
	oe.customers.credit_limit,
	oe.customers.gender;

Problem 67
For each order, retrieve the order ID, order date, customer ID, order total, and sales rep ID. Sort the result set by customer ID (ascending) and order date (ascending).
Solution

SELECT
	oe.orders.order_id,
	oe.orders.order_date,
	oe.orders.customer_id,
	oe.orders.order_total,
	oe.orders.sales_rep_id
FROM
	oe.orders
ORDER BY
	oe.orders.customer_id,
	oe.orders.order_date;

Problem 68
Retrieve only those orders with an order total greater than $100,000. Include the order ID, order date, customer ID, order total, and sales rep ID for each order. Sort the result set by customer ID (ascending) and order date (ascending).
Solution

SELECT
	oe.orders.order_id,
	oe.orders.order_date,
	oe.orders.customer_id,
	oe.orders.order_total,
	oe.orders.sales_rep_id
FROM
	oe.orders
WHERE
	oe.orders.order_total > 100000
ORDER BY
	oe.orders.customer_id,
	oe.orders.order_date;

Problem 69
For each order, retrieve the order ID, line-item ID, product ID, unit price, and quantity of the first line item.
Solution

SELECT
	oe.order_items.order_id,
	oe.order_items.line_item_id,
	oe.order_items.product_id,
	oe.order_items.unit_price,
	oe.order_items.quantity
FROM
	oe.order_items
WHERE
	oe.order_items.line_item_id = 1;

Problem 70
For each order, retrieve the order ID, order date, and order total. Only include those orders with an order total between $75,000 and $100,000, inclusive. Sort the result set by order total, descending.
Solution

SELECT
	oe.orders.order_id,
	oe.orders.order_date,
	oe.orders.order_total
FROM
	oe.orders
WHERE
	oe.orders.order_total BETWEEN 75000 AND 100000
ORDER BY
	oe.orders.order_total DESC;

Problem 71
Retrieve all customers with a national language support territory (nls_territory) of America, India, or China. Include the customer ID, customer first name, customer last name, and NLS territory for each customer. Sort the result set by NLS territory (ascending) and customer ID (ascending).
Solution

SELECT
	oe.customers.customer_id,
	oe.customers.cust_first_name,
	oe.customers.cust_last_name,
	oe.customers.nls_territory
FROM
	oe.customers
WHERE
	oe.customers.nls_territory IN ('AMERICA', 'INDIA', 'CHINA')
ORDER BY
	oe.customers.nls_territory,
	oe.customers.customer_id;

Problem 72
Retrieve product information for all products with product names starting with ‘Inkjet.’ Include the product ID, product name, and product description for each product.
Solution

SELECT
	oe.product_information.product_id,
	oe.product_information.product_name,
	oe.product_information.product_description
FROM
	oe.product_information
WHERE
	oe.product_information.product_name LIKE 'Inkjet%';

Problem 73
Retrieve the product ID, supplier ID, and catalog URL for products with a catalog URL containing the string, 102094.
Solution

SELECT
	oe.product_information.product_id,
	oe.product_information.supplier_id,
	oe.product_information.catalog_url
FROM
	oe.product_information
WHERE
	oe.product_information.catalog_url LIKE '%102094%';

Problem 74
Retrieve the order ID, order date, order total, customer ID, and sales rep ID. Only include online orders in your result set. Assume all orders without a sales rep ID are online orders.
Solution

SELECT
	oe.orders.order_id,
	oe.orders.order_date,
	oe.orders.order_total,
	oe.orders.customer_id,
	oe.orders.sales_rep_id
FROM
	oe.orders
WHERE
	oe.orders.sales_rep_id IS NULL;

Problem 75
Retrieve online orders. Only include online orders placed in year 2007 or online orders with an order total greater than or equal to $100,000. Include the order ID, order date, order total, and sales rep ID for each online order. Assume all orders without a sales rep ID are online orders. Sort the result set by order date, ascending.
Solution

SELECT
	oe.orders.order_id,
	oe.orders.order_date,
	oe.orders.order_total,
	oe.orders.sales_rep_id
FROM
	oe.orders
WHERE
    oe.orders.sales_rep_id IS NULL
	AND (oe.orders.order_date BETWEEN '01-JAN-07' AND '31-DEC-07'
		OR oe.orders.order_total >= 100000)
ORDER BY
	oe.orders.order_date;

Problem 76
Retrieve product information for products that have a minimum price greater than or equal to $1,000 or less than or equal to $10. In addition, only include products with a category ID of 19. Include the product ID, product name, category ID, and minimum price for each product. Sort the result set by minimum price, descending.
Solution

SELECT
	oe.product_information.product_id,
	oe.product_information.product_name,
	oe.product_information.category_id,
	oe.product_information.min_price
FROM
	oe.product_information
WHERE
	(oe.product_information.min_price >= 1000
		OR oe.product_information.min_price <= 10)
	AND oe.product_information.category_id = 19
ORDER BY
	oe.product_information.min_price DESC;

Problem 77
Compute/retrieve the minimum order total, maximum order total, sum of all order totals, the number of orders placed, and the average of all order totals. Provide meaningful aliases/names to the derived columns.
Solution

SELECT
	MIN(oe.orders.order_total) AS min_order_total,
	MAX(oe.orders.order_total) AS max_order_total,
	SUM(oe.orders.order_total) AS order_total,
	COUNT(oe.orders.order_total) AS order_count,
	AVG(oe.orders.order_total) AS average_order_total
FROM
	oe.orders;

Problem 78
For each customer, compute/retrieve the minimum order total, maximum order total, sum of all order totals, the number of orders placed, and the average of all order totals. Provide meaningful aliases/names to the derived columns. The customer ID should be the first column in your result set. Sort the result set by the sum of order totals, descending.
Solution

SELECT
	oe.orders.customer_id,
	MIN(oe.orders.order_total) AS min_order_total,
	MAX(oe.orders.order_total) AS max_order_total,
	SUM(oe.orders.order_total) AS order_total,
	COUNT(oe.orders.order_total) AS order_count,
	AVG(oe.orders.order_total) AS average_order_total
FROM
	oe.orders
GROUP BY
	oe.orders.customer_id
ORDER BY
	SUM(oe.orders.order_total) DESC;

Problem 79
For each product ID, compute/retrieve the number orders placed for that item. The product ID should be the first column in your result set. Provide a meaningful alias/name to the derived column. Sort the result set by the number of times a product was ordered, descending.
Solution

SELECT
	oe.order_items.product_id,
	COUNT(oe.order_items.product_id) AS order_count
FROM
	oe.order_items
GROUP BY
	oe.order_items.product_id
ORDER BY
	order_count DESC;

Problem 80
For each existing account manager ID and credit limit combination, compute/retrieve the number of customers aligned to the manager ID and credit limit combination. Account manager ID and credit limit should be included in your result set. Provide a meaningful alias/name to the derived column. Sort the result set by account manager ID (ascending) and by credit limit (descending).
Solution

SELECT
	oe.customers.account_mgr_id,
	oe.customers.credit_limit,
	COUNT(oe.customers.credit_limit) AS customer_count
FROM
	oe.customers
GROUP BY
	oe.customers.account_mgr_id,
	oe.customers.credit_limit
ORDER BY
	oe.customers.account_mgr_id,
	oe.customers.credit_limit DESC;

Problem 81
Retrieve the number of products containing product information for each product category ID. Only include those product category IDs with more than 25 products aligned to the product category ID. The product category ID should be the first column in your result set. Provide a meaningful alias/name to the derived column. Sort the result set by the number of products in each product category ID, descending.
Solution

SELECT
	oe.product_information.category_id,
	COUNT(oe.product_information.category_id) AS product_count
FROM
	oe.product_information
GROUP BY
	oe.product_information.category_id
HAVING
	COUNT(oe.product_information.category_id) > 25
ORDER BY
	product_count DESC;

Problem 82
For each customer that has placed an order, compute/retrieve the date the customer made their first order and the sum of all order totals. Only include customers that made their first order before year 2007 and have a sum of all order totals greater than $150,000. The customer ID should be the first column in your result set. Provide meaningful aliases/names to the derived columns. Sort the result set by the first order’s order date.
Solution

SELECT
	oe.orders.customer_id,
	MIN(oe.orders.order_date) AS first_order_date,
	SUM(oe.orders.order_total) AS order_total
FROM
	oe.orders
GROUP BY
	oe.orders.customer_id
HAVING
	MIN(oe.orders.order_date) <= '31-DEC-06'
	AND SUM(oe.orders.order_total) > 150000
ORDER BY
	MIN(oe.orders.order_date);

Problem 83
Retrieve the daily product category sales for April 2023. In the output, include the report date, product category, and total sales. Sort the result set in ascending order by report date and product category.

Table Required

north_america_sale

Expected Output
report_dateproduct_categorytotal_sale
01-APR-23Hardware390594
01-APR-23Office Supplies320527
01-APR-23Software141595
02-APR-23Hardware464361
02-APR-23Office Supplies487635
02-APR-23Software183160
03-APR-23Hardware487048
03-APR-23Office Supplies109011
03-APR-23Software179908
04-APR-23Hardware437387
04-APR-23Office Supplies171126
04-APR-23Software156679
05-APR-23Hardware163396
05-APR-23Office Supplies299903
05-APR-23Software125223
06-APR-23Hardware241845
06-APR-23Office Supplies442197
06-APR-23Software121008
07-APR-23Hardware454711
07-APR-23Office Supplies405102
07-APR-23Software221383
08-APR-23Hardware251905
08-APR-23Office Supplies220887
08-APR-23Software107507
09-APR-23Hardware227411
09-APR-23Office Supplies265518
09-APR-23Software310617
10-APR-23Hardware310046
10-APR-23Office Supplies150205
10-APR-23Software422232
11-APR-23Hardware320621
11-APR-23Office Supplies411607
11-APR-23Software332198
12-APR-23Hardware274390
12-APR-23Office Supplies366354
12-APR-23Software384063
13-APR-23Hardware382678
13-APR-23Office Supplies169193
13-APR-23Software280966
14-APR-23Hardware158199
14-APR-23Office Supplies405273
14-APR-23Software288234
15-APR-23Hardware375867
15-APR-23Office Supplies242540
15-APR-23Software312305
16-APR-23Hardware306784
16-APR-23Office Supplies410744
16-APR-23Software457762
17-APR-23Hardware128819
17-APR-23Office Supplies393735
17-APR-23Software134756
18-APR-23Hardware277928
18-APR-23Office Supplies185693
18-APR-23Software156509
19-APR-23Hardware352213
19-APR-23Office Supplies118006
19-APR-23Software475899
20-APR-23Hardware105392
20-APR-23Office Supplies274407
20-APR-23Software486045
21-APR-23Hardware412107
21-APR-23Office Supplies307669
21-APR-23Software137841
22-APR-23Hardware440743
22-APR-23Office Supplies211778
22-APR-23Software420618
23-APR-23Hardware306189
23-APR-23Office Supplies446075
23-APR-23Software437481
24-APR-23Hardware309242
24-APR-23Office Supplies300044
24-APR-23Software369096
25-APR-23Hardware433689
25-APR-23Office Supplies330579
25-APR-23Software347470
26-APR-23Hardware465270
26-APR-23Office Supplies458689
26-APR-23Software147642
27-APR-23Hardware345373
27-APR-23Office Supplies256230
27-APR-23Software131632
28-APR-23Hardware478742
28-APR-23Office Supplies487975
28-APR-23Software159253
29-APR-23Hardware308098
29-APR-23Office Supplies172834
29-APR-23Software235898
30-APR-23Hardware370109
30-APR-23Office Supplies279783
30-APR-23Software429613
Solution
SELECT
	north_america_sale.report_date,
    north_america_sale.product_category,
    north_america_sale.total_sale
FROM
	north_america_sale
WHERE
	north_america_sale.report_date >= '01-APR-23'
	AND north_america_sale.report_date < '01-MAY-23'
ORDER BY
    north_america_sale.report_date,
    north_america_sale.product_category;

Problem 84
Building onto your solution from problem 83, retrieve only those daily sales for the Software product category. Remove the sorting based on product category.

Table Required

north_america_sale

Expected Output
report_dateproduct_categorytotal_sale
01-APR-23Software141595
02-APR-23Software183160
03-APR-23Software179908
04-APR-23Software156679
05-APR-23Software125223
06-APR-23Software121008
07-APR-23Software221383
08-APR-23Software107507
09-APR-23Software310617
10-APR-23Software422232
11-APR-23Software332198
12-APR-23Software384063
13-APR-23Software280966
14-APR-23Software288234
15-APR-23Software312305
16-APR-23Software457762
17-APR-23Software134756
18-APR-23Software156509
19-APR-23Software475899
20-APR-23Software486045
21-APR-23Software137841
22-APR-23Software420618
23-APR-23Software437481
24-APR-23Software369096
25-APR-23Software347470
26-APR-23Software147642
27-APR-23Software131632
28-APR-23Software159253
29-APR-23Software235898
30-APR-23Software429613
Solution
SELECT
	north_america_sale.report_date,
    north_america_sale.product_category,
    north_america_sale.total_sale
FROM
	north_america_sale
WHERE
	north_america_sale.report_date >= '01-APR-23'
	AND north_america_sale.report_date < '01-MAY-23'
	AND north_america_sale.product_category = 'Software'
ORDER BY
    north_america_sale.report_date;

Problem 85
Compute the total sales across all product categories for each day occurring in the months of July, August, and September of 2023. Alias the computed sale amount column as ‘daily_total_sale’. In the output, include the report date and daily total sales. Sort the result set in ascending order by report date.

Table Required

north_america_sale

Expected Output
report_datedaily_total_sale
01-JUL-23814774
02-JUL-23826253
03-JUL-23776726
04-JUL-23511317
05-JUL-23806657
06-JUL-23779799
07-JUL-231147623
08-JUL-23604928
09-JUL-23907319
10-JUL-23565389
11-JUL-231124202
12-JUL-23943577
13-JUL-231205384
14-JUL-231187425
15-JUL-231051398
16-JUL-231057940
17-JUL-23415800
18-JUL-23721071
19-JUL-23647166
20-JUL-23530326
21-JUL-23697593
22-JUL-23580278
23-JUL-23651665
24-JUL-23988073
25-JUL-23992175
26-JUL-231010617
27-JUL-231109915
28-JUL-23995753
29-JUL-231010636
30-JUL-23996739
31-JUL-23890989
01-AUG-23695166
02-AUG-23371637
03-AUG-23869690
04-AUG-231034226
05-AUG-231028273
06-AUG-231195365
07-AUG-23965429
08-AUG-23723448
09-AUG-23923629
10-AUG-231260461
11-AUG-23830229
12-AUG-23800827
13-AUG-231108060
14-AUG-23783417
15-AUG-231078274
16-AUG-23944669
17-AUG-23972297
18-AUG-23765486
19-AUG-23858946
20-AUG-231420514
21-AUG-231060476
22-AUG-23863389
23-AUG-23947669
24-AUG-23576202
25-AUG-23876318
26-AUG-23796264
27-AUG-231100756
28-AUG-23628789
29-AUG-231026234
30-AUG-23979660
31-AUG-23647812
Solution
SELECT
	north_america_sale.report_date,
    SUM(north_america_sale.total_sale) AS daily_total_sale
FROM
	north_america_sale
WHERE
	north_america_sale.report_date >= '01-JUL-23'
	AND north_america_sale.report_date < '01-SEP-23'
GROUP BY
    north_america_sale.report_date
ORDER BY
	north_america_sale.report_date;

Problem 86
Building onto your previous solution from problem 85, only include those days where the daily total sales amount is greater than 1,000,000. Sort the result set in ascending order by report date.

Table Required

north_america_sale

Expected Output
report_datedaily_total_sale
07-JUL-231147623
11-JUL-231124202
13-JUL-231205384
14-JUL-231187425
15-JUL-231051398
16-JUL-231057940
26-JUL-231010617
27-JUL-231109915
29-JUL-231010636
04-AUG-231034226
05-AUG-231028273
06-AUG-231195365
10-AUG-231260461
13-AUG-231108060
15-AUG-231078274
20-AUG-231420514
21-AUG-231060476
27-AUG-231100756
29-AUG-231026234
Solution
SELECT
	north_america_sale.report_date,
    SUM(north_america_sale.total_sale) AS daily_total_sale
FROM
	north_america_sale
WHERE
	north_america_sale.report_date >= '01-JUL-23'
	AND north_america_sale.report_date < '01-SEP-23'
GROUP BY
    north_america_sale.report_date
HAVING
    SUM(north_america_sale.total_sale) > 1000000
ORDER BY
	north_america_sale.report_date;

Problem 87
For each member type, compute the total number of members. Alias the total number of members of each member type as “member_count.” In the output, include the member type ID and member count. Sort the result set in descending order by member_count.

Table Required

member

Expected Output
member_type_idmember_count
525
222
319
119
415
Solution
SELECT
    member.member_type_id,
	COUNT(member.member_type_id) AS member_count
FROM
	member
GROUP BY
    member.member_type_id
ORDER BY
    COUNT(member.member_type_id) DESC;

Problem 88
For each employee, compute the total number of members enrolled. Alias the total number of members of each member type as “enrollment_count.” In the output, include the employee ID and enrollment count. Sort the result set in descending order by enrollment_count.

Table Required

member

Expected Output
employee_idenrollment_count
521
615
215
314
412
110
79
83
101
Solution
SELECT
    member.employee_id,
	COUNT(member.member_id) AS enrollment_count
FROM
	member
GROUP BY
    member.employee_id
ORDER BY
    COUNT(member.member_id) DESC;

Problem 89
Compute the average, minimum, maximum, and range (i.e., maximum – minimum) of using all the prices of all products. Provide meaningful aliases/names to the derived columns.

Table Required

product

Expected Output
average_pricemaximum_priceminimum_priceprice_range
2.81253.521.5
Solution
SELECT
    AVG(product.price) AS average_price,
	MAX(product.price) AS maximum_price,
	MIN(product.price) AS minimum_price,
	MAX(product.price) - MIN(product.price) AS price_range
FROM
	product;

Problem 90
Write a query that returns a result set containing the product ID, description, and price for those products with a description containing the sequence of characters, “Chocolate.”

Table Required

product

Expected Output
product_iddescriptionprice
2Chocolate2
4Mint Chocolate Chip3
5Chocolate Chip Cookie Dough3.5
Solution
SELECT
	product.product_id,
	product.description,
    product.price
FROM
	product
WHERE
    product.description LIKE '%Chocolate%';

Problem 91
Compute the number of members enrolled each day based on the member enrollment date values. Alias the number of members enrolled as “enrollment_count.” In the output, include the enrollment date and enrollment count. Sort the result set in ascending order by enrollment_date.

Table Required

member

Expected Output
enrollment_dateenrollment_count
01-JAN-241
02-JAN-242
03-JAN-241
05-JAN-241
10-JAN-242
11-JAN-242
12-JAN-241
13-JAN-241
14-JAN-241
15-JAN-241
16-JAN-242
17-JAN-242
19-JAN-243
20-JAN-242
22-JAN-241
26-JAN-245
27-JAN-242
30-JAN-241
31-JAN-242
02-FEB-241
04-FEB-241
05-FEB-242
08-FEB-241
09-FEB-242
10-FEB-242
11-FEB-241
13-FEB-243
15-FEB-242
16-FEB-242
17-FEB-241
18-FEB-242
19-FEB-241
20-FEB-242
21-FEB-242
22-FEB-243
23-FEB-241
25-FEB-242
26-FEB-243
27-FEB-242
28-FEB-241
01-MAR-242
02-MAR-242
03-MAR-242
04-MAR-241
05-MAR-241
06-MAR-242
11-MAR-242
13-MAR-241
14-MAR-241
15-MAR-241
18-MAR-241
21-MAR-243
22-MAR-243
24-MAR-241
25-MAR-242
26-MAR-241
27-MAR-241
29-MAR-242
30-MAR-241
Solution
SELECT
	member.enrollment_date,
    COUNT(member.member_id) AS enrollment_count
FROM
	member
GROUP BY
    member.enrollment_date
ORDER BY
    member.enrollment_date;

Problem 92
Building onto your previous solution from problem 91, only include those days where the number of members enrolled is at least 3.

Table Required

member

Expected Output
enrollment_dateenrollment_count
19-JAN-243
26-JAN-245
13-FEB-243
22-FEB-243
26-FEB-243
21-MAR-243
22-MAR-243
Solution
SELECT
	member.enrollment_date,
    COUNT(member.member_id) AS enrollment_count
FROM
	member
GROUP BY
    member.enrollment_date
HAVING
	COUNT(member.member_id) >= 3
ORDER BY
    member.enrollment_date;

Problem 93
Retrieve member details for those members enrolled by the employee with an ID value of 1 or with an enrollment date occurring within the month of March 2024. In the output, include the member ID, member type ID, enrollment date, email address, and employee ID.

Table Required

member

Expected Output
member_idmember_type_idenrollment_dateemail_addressemployee_id
10112-JAN-24NM2HWVNQ1G@example.com1
11213-JAN-24G15RO0FJ1W@example.com1
13515-JAN-24SXIK09W9ET@example.com1
18319-JAN-24G0XCM7EGF8@example.com1
19319-JAN-24M7Y3YFLF9E@example.com1
20219-JAN-240R350BCG4A@example.com1
47215-FEB-24SU1NNV198S@example.com1
48115-FEB-2486TFB7ILY4@example.com1
57121-FEB-24NMCHWP0Z1U@example.com1
58321-FEB-24F3AXG158RH@example.com1
71301-MAR-247SCHXCBAG7@example.com3
72401-MAR-24IMG7HY0N5Y@example.com3
73502-MAR-24G2REPPIBPK@example.com3
74502-MAR-24AR7Q3N45OR@example.com3
75303-MAR-24CWIR32Q5G7@example.com6
76203-MAR-24TV29AL4ZC8@example.com6
77104-MAR-24WT2V2YQYGM@example.com2
78205-MAR-24WB9C308F4Y@example.com7
79406-MAR-24AP7VVCJBMJ@example.com2
80206-MAR-2498BZXTH795@example.com2
81311-MAR-24B9KXURD43L@example.com8
82311-MAR-244OEJT5HWZZ@example.com8
83513-MAR-241ZDVN3XAHA@example.com10
84114-MAR-246HREL4BM07@example.com5
85515-MAR-24G5L5J47BIX@example.com4
86418-MAR-24DFUM3QJ7WY@example.com2
87521-MAR-24IWPCD8NOXV@example.com6
88121-MAR-24SD7QUPAIF6@example.com6
89221-MAR-24R0DAIBETI4@example.com6
90122-MAR-24NVRQU7A8U6@example.com6
91422-MAR-245QH0YE66H0@example.com6
92322-MAR-24QH4ZIISQUT@example.com6
93424-MAR-2414JH7VV2ZP@example.com8
94525-MAR-24PCRPK8EZXO@example.com2
95325-MAR-24YDAEZK2Q0J@example.com2
96326-MAR-243EHNYXQGPE@example.com4
97127-MAR-24HS6PYYP8IS@example.com3
98129-MAR-2405U625H1CU@example.com6
99129-MAR-24WDR4VOPPWR@example.com6
100130-MAR-24STO9IYZMFK@example.com6
Solution
SELECT
    member.member_id,
	member.member_type_id,
	member.enrollment_date,
	member.email_address,
	member.employee_id
FROM
	member
WHERE
	member.employee_id = 1
	OR (
    	enrollment_date >= '01-MAR-24'
    	AND enrollment_date < '01-APR-24'
    );

Problem 94
Compute the number of members associated with each member type. Alias the number of members as “member_count.” In the output, include the member type ID and member count. Sort the result set in ascending order by member type ID.

Table Required

member

Expected Output
member_type_idmember_count
119
222
319
415
525
Solution
SELECT
	member.member_type_id,
    COUNT(member.member_id) AS member_count
FROM
	member
GROUP BY
	member.member_type_id
ORDER BY
	member_type_id;

Problem 95
Write a query that returns a result set containing the employee ID, last name, first name, hire date, job ID, and salary for those employees hired prior to the ice cream shop’s opening date (i.e., January 1, 2024).

Table Required

employee

Expected Output
employee_idlast_namefirst_namehire_datejob_idsalary
1CooleySonia01-DEC-23100160000
2EdwardsJason15-DEC-23100245000
3WilliamsKelly15-DEC-23100245000
4PowersDarren15-DEC-23100334290
5BrockmanTim15-DEC-23100335172
Solution
SELECT
	employee.employee_id,
    employee.last_name,
    employee.first_name,
    employee.hire_date,
    employee.job_id,
    employee.salary
FROM
	employee
WHERE
    employee.hire_date < '01-JAN-24';

Problem 96
Adjust your solution to problem 96 to compute the number of employees hired prior to the ice cream shop’s opening date (i.e., January 1, 2024). Alias the number of employees hired as “employee_count.”

Table Required

employee

Expected Output
employee_count
5
Solution
SELECT
	COUNT(employee.employee_id) AS employee_count
FROM
	employee
WHERE
    employee.hire_date < '01-JAN-24';

Problem 97
Building onto your solution to the previous problem, break out the total number of employees hired by job ID value. There should be one row per job ID value and the corresponding employee count.

Table Required

employee

Expected Output
job_idemployee_count
10011
10022
10032
Solution
SELECT
	employee.job_id,
	COUNT(employee.employee_id) AS employee_count
FROM
	employee
WHERE
    employee.hire_date < '01-JAN-24'
GROUP BY
	employee.job_id;

Problem 98
Compute the average salary for each job. Only include those job ID values where more than one employee holds the corresponding job. Alias the average salary column as “average_salary.” In the output, include the job ID corresponding average salary.

Table Required

employee

Expected Output
job_idaverage_salary
100245000
100333865
Solution
SELECT
	employee.job_id,
    AVG(employee.salary) AS average_salary
FROM
	employee
GROUP BY
	employee.job_id
HAVING
	COUNT(employee.employee_id) > 1;

Problem 99
Compute the ice cream shop’s daily sales. Alias the daily sales column as “daily_sales.” In the output, include the purchase date and daily sales. Sort the result set in ascending order by purchase date.

Table Required

purchase

Expected Output
purchase_datedaily_sales
01-JAN-2415
02-JAN-2462.81
03-JAN-2425.2
05-JAN-241.8
10-JAN-2424.71
11-JAN-2413.83
12-JAN-2412
13-JAN-245.82
14-JAN-248.55
15-JAN-2412.6
16-JAN-2435.55
17-JAN-2432.49
19-JAN-2427.37
20-JAN-2427.65
22-JAN-243.26
26-JAN-2450.4
27-JAN-2413.71
30-JAN-2423.25
31-JAN-2436
02-FEB-2414.3
04-FEB-2411.5
05-FEB-2427.6
07-FEB-2425.65
08-FEB-2421.6
09-FEB-2428.28
10-FEB-2411.02
11-FEB-2415.93
13-FEB-2434.79
15-FEB-2444.43
16-FEB-2432.85
17-FEB-2424.5
18-FEB-2421.39
19-FEB-2414
20-FEB-2445.29
21-FEB-2433.95
22-FEB-2464.54
23-FEB-2449.95
25-FEB-2448.7
26-FEB-2436.3
27-FEB-2458.88
28-FEB-2410.88
29-FEB-2420.12
01-MAR-2451.12
02-MAR-2427.42
03-MAR-2453.67
04-MAR-2441.35
05-MAR-2464.66
06-MAR-2431.85
07-MAR-2458.62
08-MAR-2418
10-MAR-2414.07
11-MAR-2466.35
12-MAR-243.26
13-MAR-2437.91
14-MAR-2419.5
15-MAR-2438.25
16-MAR-2415.52
17-MAR-2435.05
18-MAR-2449.14
19-MAR-2427.31
20-MAR-246.3
21-MAR-2472.97
22-MAR-2475.09
23-MAR-2422.47
24-MAR-2475.8
25-MAR-2456.95
26-MAR-24124.67
27-MAR-24150.23
28-MAR-2439.53
29-MAR-2474.54
30-MAR-2458.17
31-MAR-24137.75
Solution
SELECT
    purchase_date,
	SUM(purchase_total) AS daily_sales
FROM
	purchase
GROUP BY
    purchase_date
ORDER BY
    purchase_date;

Problem 100
Retrieve the purchase details for purchases where the total purchase value exceeds $10, and the purchase date is in January 2024. In the output, include the purchase ID, member ID, purchase date, employee ID, and purchase total. Sort the result set in ascending order by purchase date.

Table Required

purchase

Expected Output
purchase_idmember_idpurchase_dateemployee_idpurchase_total
1101-JAN-24215
2202-JAN-24428.8
4302-JAN-24432.01
5403-JAN-24425.2
8610-JAN-24522.81
10911-JAN-24510.23
111012-JAN-24512
141315-JAN-24512.6
151416-JAN-24118.9
161516-JAN-24116.65
171617-JAN-24317.46
19717-JAN-24311.88
222019-JAN-24213.59
232120-JAN-24410.19
242220-JAN-24417.46
262426-JAN-24423.28
272526-JAN-24411.5
333130-JAN-24523.25
353231-JAN-24128.8
Solution
SELECT
	purchase.purchase_id,
    purchase.member_id,
    purchase.purchase_date,
    purchase.employee_id,
    purchase.purchase_total
FROM
	purchase
WHERE
	purchase.purchase_total >= 10
    AND purchase.purchase_date >= '01-JAN-24'
    AND purchase.purchase_date < '01-FEB-24'
ORDER BY
    purchase_date;

Problem 101
For each member, compute the total amount spent. Alias this computed amount as “total_sales.” In the output, include the member ID and total sales. Sort the result set in descending order by total sales.

Table Required

purchase

Expected Output
member_idtotal_sales
8470
3166.5
9865
5960.15
9658.44
6058.05
7157.96
3956.75
9753.5
550.85
650.84
6847.25
9547.03
7046.56
345.6
1444.55
4744.14
8243.7
7842.69
5341.85
9241.81
2739.9
6138.5
6936.86
7936.28
3335.55
4835
4633.48
4533.3
5033.02
8833
10032
9431.95
8131.35
7530.88
7230.69
1330.6
5630.56
9030
6330
7429.7
4429.59
228.8
3228.8
4928.35
1527
5727
2525.5
1625.22
425.2
8725.2
3024.75
4024.7
2224.25
1923.75
2423.28
6722.5
4222.33
5222.32
3821.6
7721
8619.53
1019
9118.6
1218.05
5117.5
117
5516.63
9916.5
3716.2
1114.55
5414
713.78
2013.59
6213.58
7312.6
6411.4
3611.4
1711.25
910.23
2110.19
839.45
299.3
859
359
438.73
417.76
767.76
587.13
236.52
936.51
286.51
895.82
665.4
265.23
185.23
344.85
83.6
802.91
652.7
Solution
SELECT
    purchase.member_id,
    SUM(purchase.purchase_total) AS total_sales
FROM
	purchase
GROUP BY
    purchase.member_id
ORDER BY
    SUM(purchase.purchase_total) DESC;

Problem 102
Building onto your solution to the previous problem, only include those members with a total sales value greater than or equal to $50 and more than three purchases.

Table Required

purchase

Expected Output
member_idtotal_sales
8470
7157.96
3956.75
550.85
Solution
SELECT
    purchase.member_id,
    SUM(purchase.purchase_total) AS total_sales
FROM
	purchase
GROUP BY
    purchase.member_id
HAVING
    SUM(purchase.purchase_total) >= 50
    AND COUNT(purchase.purchase_id) > 3
ORDER BY
    SUM(purchase.purchase_total) DESC;

Problem 103
Compute the distinct number of times each product has been purchased. Alias this computed value as “purchase_count.” In the output, include the product ID and purchase count. Sort the result set in descending order by purchase count.

Table Required

purchase_item

Expected Output
product_idpurchase_count
357
752
452
644
544
842
140
237
Solution
SELECT
	purchase_item.product_id,
    COUNT(purchase_item.purchase_id) AS purchase_count
FROM
	purchase_item
GROUP BY
	purchase_item.product_id
ORDER BY
    COUNT(purchase_item.purchase_id) DESC;

Problem 104
For each purchase, compute the total number of items purchased based on quantity. Alias this computed value as “item_count.” In the output, include the purchase ID and item count. Sort the result set in descending order by item count.

Table Required

purchase_item

Expected Output
purchase_idtotal_quantity
19214
19714
10013
9412
15912
211
5411
8911
19911
411
1510
11810
13010
3510
15710
11510
649
1139
429
1069
339
249
59
1738
858
1628
1848
1858
1208
1818
1498
1528
958
1198
1338
1718
268
1077
1387
1617
437
787
1687
1837
2007
637
1967
87
567
707
667
1037
1697
1127
1467
1087
16
166
886
1276
1316
1636
1726
416
1796
176
766
1746
1376
1866
536
976
1446
686
275
1755
585
1055
1105
1985
445
1405
1455
1555
1775
1955
815
605
1675
1175
515
144
504
574
1254
1584
404
714
994
1434
1804
1894
344
454
624
114
774
1874
104
484
1014
1514
1784
224
934
964
194
294
694
1114
1144
1394
614
1234
1504
1604
1654
233
1543
1243
313
793
823
1293
123
373
843
1213
1413
493
653
203
463
743
873
1263
1483
1703
133
1323
1933
323
393
803
923
1023
523
722
1762
362
592
1342
1362
1902
212
732
752
862
902
1912
1162
1422
1562
92
282
672
1532
1642
912
1472
1352
61
1821
71
981
1091
1041
301
1881
1941
181
31
1221
1281
381
551
831
251
471
1661
Solution
SELECT
	purchase_item.purchase_id,
    SUM(purchase_item.quantity) AS total_quantity
FROM
	purchase_item
GROUP BY
	purchase_item.purchase_id
ORDER BY
	SUM(purchase_item.quantity) DESC;

Problem 105
Retrieve the purchase ID values for those purchases containing product ID values 1, 4, or 8. In the output, include the purchase ID.

Table Required

purchase_item

Expected Output
purchase_id
6
27
50
51
57
107
113
124
125
161
166
7
15
31
36
40
42
43
68
98
99
109
110
131
136
159
180
183
189
34
41
44
45
63
82
104
118
129
184
185
196
2
11
17
21
30
54
56
70
73
84
86
90
115
121
140
145
155
177
191
194
4
5
10
35
48
49
65
66
81
101
103
116
120
137
151
157
169
197
199
3
9
33
74
87
93
112
128
149
19
29
38
55
83
95
133
144
164
193
16
24
32
39
61
80
89
100
102
117
138
147
160
165
192
Solution
SELECT
	DISTINCT purchase_item.purchase_id
FROM
	purchase_item
WHERE
	purchase_item.product_id IN (1, 4, 8);