Using SQL statements in MySQL
(1) Find the position number, title, employer and salary of positions that have been applied by the most amounts of applicants.
(2) Find the applicant number, full name of applicants
that possessed all skills needed by a position 00000005.
Note that an applicant possessed all skills needed by a position
means all skills (sname) needed are possessed by the
applicant,
and the skill levels (skilllevel) that needed less or equals to the
correspondent skill levels the applicant possessed.
1.SELECT P.pnumber,P.ptitle,P.employer,P.salary
FROM Position P INNER JOIN applies A ON A.pnumber =P.pnumber
Group By P.pnumber
HAVING COUNT(A.anumber) =
(SELECT MAX(No_Of_application) FROM(
Select COUNT(anumber) as No_Of_application From Applies
Group By pnumber));
EXPLANATION:-
We use SELECT tofetch data from the table.
We are using INNER JOIN to combine the tables Position and applies, then we group the results by position number.
HAVING clause is used to check for count of applicants applied for position using COUNT() function.
Now, in sub query part we are getting maximum of the of the applicant applied for any position using GROUP BY clause from applies table and MAX() aggregate function.
Then we are comparing this result with the count .This is done to get the multiple position with maximum applicant.
2.SELECT A.anumber ,CONCAT(A.fname,' ',A.lname) AS Name FROM
Applicant A INNER JOIN SPossessed SP ON SP.anumber=A.anumber
INNER JOIN SNeeded SN ON SN.sname=SP.sname AND SP.slevel >=SN.slevel
WHERE SN.pnumber =00000005
Group BY anumber
HAVING COUNT(SP.sname) =(SELECT COUNT(sname) FROM SNeeded WHERE pnumber =00000005) ;
EXPLANATION:-
Here, we are using CONCAT() function to combine the first name and last name to get the full name.
Then we combine different tables using INNER JOIN.
While joining SNeeded table we checked for Sname as well as slevel possessed by applicant to be greater or equal to level needed for position number 00000005.
Where clause is used to filter the data on the basis pnumber.
Then GROUP BY is used for grouping by anumber.
Then we are checking count of all these skills using HAVING clause to check whether it is equal to the the number skills needed for pnumber 00000005.
Using SQL statements in MySQL (1) Find the position number, title, employer and salary of positions...
SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...