Say we have
SELECT [DISTINCT] target-list
FROM relation-list
WHERE qualification
GROUP BY grouping-list
HAVING group-qualification
,where the target-list contains (i) attribute names (ii) terms with aggregate operations (e.g., MIN (S.age)).
And the question is the textbook says that The attribute names (i) must be a subset of grouping-list.
But I have tried it on MYSQL database, which turns out to be ok.
Say we have
Programmer (pid, name, age), where pid is the key.
Experience (pid, lid, proficiency), where {pid,lid} is the key.
And now I try to perform following query to find out the number of records in Experience for each programmer, along with his name and pid:
Select P.pid, P.name, count(*) AS number
FROM Programmer P, Experience E
WHERE E.pid = P.pid
GROUP BY p.pid
And this works fine and has the same result as using "GROUP BY p.pid, p.name"
So, is the textbook wrong? I really see no sense why the attribute names have to be a subset of grouping list.
Thanks!