I need to write the following queries on MYSQL: 1. Write and execute a SELECT st
ID: 3791480 • Letter: I
Question
I need to write the following queries on MYSQL: 1. Write and execute a SELECT statement that counts how many companies in the Companies table that are in FL. 2. Write and execute a SELECT statement that returns the lowest starting salary and the highest starting salary from the Jobs table. 3. Write and execute a SELECT statement that returns the average starting salary of the jobs listed in the Jobs table. 4. Write and execute a SELECT statement that returns the name of the company from the Companies table that has the most number of employees. 5. Write and execute a SELECT statement that returns the name of the company from the Companies table that has the least number of employees. 6. Write and execute a SELECT statement that returns the average starting salary for each job title. Here is a hint on how to write this query: Select JobTitle, AVG(StartingSalary) FROM Jobs GROUP BY JobTitle
Explanation / Answer
#1
SELECT count(company) FROM Companies;
#2
SELECT min(StartingSalary), max(StartingSalary) FROM Jobs;
#3
SELECT AVG(StartingSalary) FROM Jobs;
#4
SELECT companyName FROM
(SELECT companyName,count(employees) as cnt
FROM Companies
GROUP BY companyName
ORDER BY cnt DESC LIMIT 1) as T1;
#5
SELECT companyName FROM
(SELECT companyName,count(employees) as cnt
FROM Companies
GROUP BY companyName
ORDER BY cnt LIMIT 1) as T1;
#6
Select JobTitle, AVG(StartingSalary) FROM Jobs GROUP BY JobTitle;