SlideShare a Scribd company logo
1. Return the names, IDS, and average salary of the top 10 employees who are Senior Engineers
whose average salary is at least $110,000 in descending order.
2. Find the top ten employees (names, IDs and total wages) who earned equal to or more than
$200000 between 01/01/2000 and 01/01/2002. Order them in decreasing order. Assume salaries
change every 12 months. For simplicity, ignore salaries that started or ended outside of the date
range.
3. Use a subquery to display the employee number and bottom 10 average salaries of the
employees who are not 'Staff'.
It is for MySQL, so the statements are slightly fifferent than SQL etc.
Solution
CREATE TABLE employees (
emp_no INT(11) NOT NULL,
birth_date DATE NOT NULL,
first_name VARCHAR(14) NOT NULL,
last_name VARCHAR(16) NOT NULL,
gender ENUM(‘M’,’F’) NOT NULL,
hire_date DATE NOT NULL,
PRIMARY KEY(emp_no) );
CREATE TABLE departments (
dept_no CHAR(4) NOT NULL,
dept_name VARCHAR(40) NOT NULL,
PRIMARY KEY(dept_no) );
UNIQUE KEY(dept_name) );
CREATE TABLE dept_emp (
emp_no INT(11) NOT NULL,
dept_no CHAR(4) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
PRIMARY KEY(emp_no) ,
FOREIGN KEY(emp_no) REFERENCES employees(emp_no),
FOREIGN KEY(dept_no) REFERENCES departments(dept_no),
PRIMARY KEY(dept_no) );
CREATE TABLE dept_manager (
emp_no INT(11) NOT NULL,
dept_no CHAR(4) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
PRIMARY KEY(emp_no) ,
FOREIGN KEY(emp_no) REFERENCES employees(emp_no),
FOREIGN KEY(dept_no) REFERENCES departments(dept_no),
PRIMARY KEY(dept_no) );
CREATE TABLE salaries (
emp_no INT(11) NOT NULL,
salary INT(11) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
PRIMARY KEY(emp_no) );
FOREIGN KEY(emp_no) REFERENCES employees(emp_no)
);
CREATE TABLE titles (
emp_no INT(11) NOT NULL,
title VARCHAR(50) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
PRIMARY KEY(emp_no) );
FOREIGN KEY(emp_no) REFERENCES employees(emp_no)
);
WHERE avg(salary) > = $110000ORDER BY avg(salary)desc limit 0,10
2. SELECT CONCAT(last_name,first_name) AS emp_name,emp_no,salary  FROM
employees
WHERE salary>=$200000 BETWEEN 01-01-2000 AND 01-01-2001 AND|OR
salary>=$200000 BETWEEN 01-01-2001 AND 01-01-2002 ORDER BY salary desc limit 0,10
3. SELECT emp_no FROM employees
WHERE salary>(SELECT avg(salary)
FROM employees
WHERE NOT EXISTS (SELECT name FROM employees)
)
ORDER BY emp_no ASC
1- Return the names- IDS- and average salary of the top 10 employees w.docx

More Related Content

PPTX
Complex Queries using MYSQL00123211.pptx
metriohanzel
 
DOCX
Sql Queries
User1test
 
DOC
Sql task answers
Nawaz Sk
 
DOC
80 different SQL Queries with output
Nexus
 
DOC
21390228-SQL-Queries.doc
SatishReddy212
 
DOC
Database management system file
Ankit Dixit
 
PDF
DBMS Lab
Neil Mathew
 
PDF
Sql queries questions and answers
Michael Belete
 
Complex Queries using MYSQL00123211.pptx
metriohanzel
 
Sql Queries
User1test
 
Sql task answers
Nawaz Sk
 
80 different SQL Queries with output
Nexus
 
21390228-SQL-Queries.doc
SatishReddy212
 
Database management system file
Ankit Dixit
 
DBMS Lab
Neil Mathew
 
Sql queries questions and answers
Michael Belete
 

Similar to 1- Return the names- IDS- and average salary of the top 10 employees w.docx (20)

DOC
SQL practice questions - set 3
Mohd Tousif
 
PDF
Sangam 19 - Analytic SQL
Connor McDonald
 
PDF
Vijay Kumar
dezyneecole
 
DOCX
Sql file (1)
rajkumari873
 
PDF
Sql queries
Preeti Lakhani
 
PDF
database application using SQL DML statements: all types of Join, Sub-Query ...
bhavesh lande
 
PDF
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
dezyneecole
 
PDF
Sql queries
Paritosh Gupta
 
PDF
Vishwajeet Sikhwal ,BCA,Final Year 2015
dezyneecole
 
PDF
Orcl sql queries
ssuser5c7be2
 
PDF
database application using SQL DML statements: Insert, Select, Update, Delet...
bhavesh lande
 
PPTX
Analytic SQL Sep 2013
Connor McDonald
 
PDF
SQL practice questions set
Mohd Tousif
 
DOCX
Mysql and html
Sai Sathvick Chirakala
 
PDF
DBMS Notes selection projection aggregate
Sreedhar Chowdam
 
DOCX
MS Access assignment
Shri Vishwakarma Skill University
 
PPTX
Database Concepts Team Project.pptx
LizSmith823201
 
DOC
Sql queires
MohitKumar1985
 
PDF
Introduction to Databases - Assignment_1
Mohd Tousif
 
DOCX
Ravi querys 425
Sorakayala Ashok
 
SQL practice questions - set 3
Mohd Tousif
 
Sangam 19 - Analytic SQL
Connor McDonald
 
Vijay Kumar
dezyneecole
 
Sql file (1)
rajkumari873
 
Sql queries
Preeti Lakhani
 
database application using SQL DML statements: all types of Join, Sub-Query ...
bhavesh lande
 
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
dezyneecole
 
Sql queries
Paritosh Gupta
 
Vishwajeet Sikhwal ,BCA,Final Year 2015
dezyneecole
 
Orcl sql queries
ssuser5c7be2
 
database application using SQL DML statements: Insert, Select, Update, Delet...
bhavesh lande
 
Analytic SQL Sep 2013
Connor McDonald
 
SQL practice questions set
Mohd Tousif
 
Mysql and html
Sai Sathvick Chirakala
 
DBMS Notes selection projection aggregate
Sreedhar Chowdam
 
MS Access assignment
Shri Vishwakarma Skill University
 
Database Concepts Team Project.pptx
LizSmith823201
 
Sql queires
MohitKumar1985
 
Introduction to Databases - Assignment_1
Mohd Tousif
 
Ravi querys 425
Sorakayala Ashok
 
Ad

More from todd991 (20)

DOCX
14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
todd991
 
DOCX
14 Income tax is estimated at 40- of income- What factors other than e.docx
todd991
 
DOCX
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
todd991
 
DOCX
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
todd991
 
DOCX
10- Consider the following data structure used for implementing a link.docx
todd991
 
DOCX
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
todd991
 
DOCX
1-What are the consequences of long term unemployment- 2-Should the go.docx
todd991
 
DOCX
1-What is the conjugate base of H2C2O4- 2-Which of the following acid.docx
todd991
 
DOCX
1-The fund financial statements for governmental funds should include.docx
todd991
 
DOCX
1-To a young researcher- what are the advantages of using the method o.docx
todd991
 
DOCX
1-The party to receive a distribution of principal from an estate is l.docx
todd991
 
DOCX
1-Consider an organization with which you have been affiliated as an e.docx
todd991
 
DOCX
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
todd991
 
DOCX
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
todd991
 
DOCX
1- You align 2 lenses together with known focal lengths fi and fa- The.docx
todd991
 
DOCX
1- What were some of the major work published by Thomas Maithus- emplo.docx
todd991
 
DOCX
1- What are the advantages and disadvantages of each of sociologys mai.docx
todd991
 
DOCX
1- What are the three fundamental elements of an effective security pr.docx
todd991
 
DOCX
1- What are the various theories that we use to explain why people com.docx
todd991
 
DOCX
1- Research has shown that a- homogeneous groups are more creative tha.docx
todd991
 
14- Which of the following is the correct name for NalICO- A- Sodiuns.docx
todd991
 
14 Income tax is estimated at 40- of income- What factors other than e.docx
todd991
 
12-19 Notes Compare and contrast the Hubble Space Telescope with James.docx
todd991
 
12-5 Distribution of Cash Upon Liquidation Manley and Singh are partne.docx
todd991
 
10- Consider the following data structure used for implementing a link.docx
todd991
 
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
todd991
 
1-What are the consequences of long term unemployment- 2-Should the go.docx
todd991
 
1-What is the conjugate base of H2C2O4- 2-Which of the following acid.docx
todd991
 
1-The fund financial statements for governmental funds should include.docx
todd991
 
1-To a young researcher- what are the advantages of using the method o.docx
todd991
 
1-The party to receive a distribution of principal from an estate is l.docx
todd991
 
1-Consider an organization with which you have been affiliated as an e.docx
todd991
 
1-Astronomers estimate that a low-mass red dwarf star like Proxima Cen.docx
todd991
 
1-a Which of TCP or UDP is connection-less- Which of TCP or UDP is con.docx
todd991
 
1- You align 2 lenses together with known focal lengths fi and fa- The.docx
todd991
 
1- What were some of the major work published by Thomas Maithus- emplo.docx
todd991
 
1- What are the advantages and disadvantages of each of sociologys mai.docx
todd991
 
1- What are the three fundamental elements of an effective security pr.docx
todd991
 
1- What are the various theories that we use to explain why people com.docx
todd991
 
1- Research has shown that a- homogeneous groups are more creative tha.docx
todd991
 
Ad

Recently uploaded (20)

PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Virus sequence retrieval from NCBI database
yamunaK13
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 

1- Return the names- IDS- and average salary of the top 10 employees w.docx

  • 1. 1. Return the names, IDS, and average salary of the top 10 employees who are Senior Engineers whose average salary is at least $110,000 in descending order. 2. Find the top ten employees (names, IDs and total wages) who earned equal to or more than $200000 between 01/01/2000 and 01/01/2002. Order them in decreasing order. Assume salaries change every 12 months. For simplicity, ignore salaries that started or ended outside of the date range. 3. Use a subquery to display the employee number and bottom 10 average salaries of the employees who are not 'Staff'. It is for MySQL, so the statements are slightly fifferent than SQL etc. Solution CREATE TABLE employees ( emp_no INT(11) NOT NULL, birth_date DATE NOT NULL, first_name VARCHAR(14) NOT NULL, last_name VARCHAR(16) NOT NULL, gender ENUM(‘M’,’F’) NOT NULL, hire_date DATE NOT NULL, PRIMARY KEY(emp_no) ); CREATE TABLE departments ( dept_no CHAR(4) NOT NULL, dept_name VARCHAR(40) NOT NULL,
  • 2. PRIMARY KEY(dept_no) ); UNIQUE KEY(dept_name) ); CREATE TABLE dept_emp ( emp_no INT(11) NOT NULL, dept_no CHAR(4) NOT NULL, from_date DATE NOT NULL, to_date DATE NOT NULL, PRIMARY KEY(emp_no) , FOREIGN KEY(emp_no) REFERENCES employees(emp_no), FOREIGN KEY(dept_no) REFERENCES departments(dept_no), PRIMARY KEY(dept_no) ); CREATE TABLE dept_manager ( emp_no INT(11) NOT NULL, dept_no CHAR(4) NOT NULL, from_date DATE NOT NULL, to_date DATE NOT NULL, PRIMARY KEY(emp_no) , FOREIGN KEY(emp_no) REFERENCES employees(emp_no), FOREIGN KEY(dept_no) REFERENCES departments(dept_no), PRIMARY KEY(dept_no) ); CREATE TABLE salaries ( emp_no INT(11) NOT NULL, salary INT(11) NOT NULL,
  • 3. from_date DATE NOT NULL, to_date DATE NOT NULL, PRIMARY KEY(emp_no) ); FOREIGN KEY(emp_no) REFERENCES employees(emp_no) ); CREATE TABLE titles ( emp_no INT(11) NOT NULL, title VARCHAR(50) NOT NULL, from_date DATE NOT NULL, to_date DATE NOT NULL, PRIMARY KEY(emp_no) ); FOREIGN KEY(emp_no) REFERENCES employees(emp_no) ); WHERE avg(salary) > = $110000ORDER BY avg(salary)desc limit 0,10 2. SELECT CONCAT(last_name,first_name) AS emp_name,emp_no,salary  FROM employees WHERE salary>=$200000 BETWEEN 01-01-2000 AND 01-01-2001 AND|OR salary>=$200000 BETWEEN 01-01-2001 AND 01-01-2002 ORDER BY salary desc limit 0,10 3. SELECT emp_no FROM employees WHERE salary>(SELECT avg(salary) FROM employees WHERE NOT EXISTS (SELECT name FROM employees) ) ORDER BY emp_no ASC