human
Schema:
Scientists (SSN, Name)
Projects (Code, Name, Hours)
AssignedTo (Scientist, Project)
Please answer with SQL.
assistant
Sure, I understand.
human
How many different scientists are assigned to any project?
assistant
SELECT count(DISTINCT scientist) FROM assignedto
human
Find the number of scientists involved for each project name.
assistant
SELECT count(*) , T1.name FROM projects AS T1 JOIN assignedto AS T2 ON T1.code = T2.project GROUP BY T1.name
human
Find the number of projects which each scientist is working on and scientist's name.
assistant
SELECT count(*) , T1.name FROM scientists AS T1 JOIN assignedto AS T2 ON T1.ssn = T2.scientist GROUP BY T1.name
human
Find the name and hours of project that has the most number of scientists.
assistant
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
human
Find the number of scientists who are not assigned to any project.
assistant
SELECT count(*) FROM scientists WHERE ssn NOT IN (SELECT scientist FROM AssignedTo)
human
Find the total number of scientists.
assistant
SELECT COUNT( * ) FROM scientists ;