Database: scientist_1

Question: Find the name of project that continues for the longest time.
SQL: SELECT name FROM projects ORDER BY hours DESC LIMIT 1

Question: List the name of all projects that are operated longer than the average working hours of all projects.
SQL: SELECT name FROM projects WHERE hours  >  (SELECT avg(hours) FROM projects)

Question: Find the name and hours of project that has the most number of scientists.
SQL: SELECT T1.name ,  T1.hours FROM projects AS T1 JOIN assignedto AS T2 ON T1.code  =  T2.project GROUP BY T2.project ORDER BY count(*) DESC LIMIT 1

Question: Find the name of the project for which a scientist whose name contains ‘Smith’ is assigned to.
SQL: SELECT T2.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project  =  T2.code JOIN scientists AS T3 ON T1.scientist  =  T3.SSN WHERE T3.name LIKE '%Smith%'

Question: Find the total hours of the projects that scientists named Michael Rogers or Carol Smith are assigned to.
SQL: SELECT sum(T2.hours) FROM assignedto AS T1 JOIN projects AS T2 ON T1.project  =  T2.code JOIN scientists AS T3 ON T1.scientist  =  T3.SSN WHERE T3.name  =  'Michael Rogers' OR T3.name  =  'Carol Smith'

Question: Find the name of the scientist who worked on both a project named 'A Matter of Time' and a project named 'A Puzzling Parallax'.
SQL: SELECT T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project  =  T2.code JOIN scientists AS T3 ON T1.scientist  =  T3.SSN WHERE T2.name  =  'Matter of Time' INTERSECT SELECT T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project  =  T2.code JOIN scientists AS T3 ON T1.scientist  =  T3.SSN WHERE T2.name  =  'A Puzzling Parallax'

Question: Find the number of scientists involved for each project name.
SQL: SELECT count(*) ,  T1.name FROM projects AS T1 JOIN assignedto AS T2 ON T1.code  =  T2.project GROUP BY T1.name

Question: Find the number of scientists involved for the projects that require more than 300 hours.
SQL: SELECT count(*) ,  T1.name FROM projects AS T1 JOIN assignedto AS T2 ON T1.code  =  T2.project WHERE T1.hours  >  300 GROUP BY T1.name

Question: Find the number of projects which each scientist is working on and scientist's name.
SQL: SELECT count(*),  T1.name FROM scientists AS T1 JOIN assignedto AS T2 ON T1.ssn  =  T2.scientist GROUP BY T1.name

Question: Find the SSN and name of scientists who are assigned to the project with the longest hours.
SQL: SELECT T3.ssn ,  T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project  =  T2.code JOIN scientists AS T3 ON T1.scientist  =  T3.SSN WHERE T2.hours  =  (SELECT max(hours) FROM projects)

Question: Select the project names which are not assigned yet.
SQL: SELECT Name FROM Projects WHERE Code NOT IN (SELECT Project FROM AssignedTo)

Question: Find the name of scientists who are not assigned to any project.
SQL: SELECT Name FROM scientists WHERE ssn NOT IN (SELECT scientist FROM AssignedTo)

Question: Find the number of scientists who are not assigned to any project.
SQL: SELECT count(*) FROM scientists WHERE ssn NOT IN (SELECT scientist FROM AssignedTo)