Problem 2b goes as follows:
问题2b如下:
2b. For each subject show the first year that the prize was awarded.
2B。每个科目都会显示奖项颁发的第一年。
nobel(yr, subject, winner)
诺贝尔(年,主题,获胜者)
My solution was this: SELECT DISTINCT subject, yr
FROM nobel
ORDER BY yr ASC;
我的解决方案是这样的:SELECT DISTINCT主题,你是来自ASC的诺贝尔奖;
Why isn't this working?
为什么这不起作用?
3 个解决方案
#1
Your answer gets a row for every distinct combination of subject and year.
对于主题和年份的每个不同组合,您的答案都会排成一行。
The correct answer GROUPS BY the subject, and gets the MIN year per subject.
正确的答案由主题组成,并获得每个科目的MIN年份。
Enough of a clue?
足够的线索?
#2
You could do it a different way without using group by or min
如果不使用group by或min,你可以采用不同的方式
select distinct subject, yr from nobel x
where yr <= all
(select yr from nobel y
where y.subject = x.subject)
but its definitely more work.
但它肯定更多的工作。
#3
SELECT subject, MIN(yr)
FROM nobel
GROUP BY subject;
Yay!
#1
Your answer gets a row for every distinct combination of subject and year.
对于主题和年份的每个不同组合,您的答案都会排成一行。
The correct answer GROUPS BY the subject, and gets the MIN year per subject.
正确的答案由主题组成,并获得每个科目的MIN年份。
Enough of a clue?
足够的线索?
#2
You could do it a different way without using group by or min
如果不使用group by或min,你可以采用不同的方式
select distinct subject, yr from nobel x
where yr <= all
(select yr from nobel y
where y.subject = x.subject)
but its definitely more work.
但它肯定更多的工作。
#3
SELECT subject, MIN(yr)
FROM nobel
GROUP BY subject;
Yay!