avatar
h*t
1
how many students participate in the most popular student activity
what's the name of this actiity
ACTIVITY (
actid number ,
activity_name varchar2(25)
);
PARTICIPATES_IN (
stuid number,
actid number
);
avatar
w*g
2
another one? :)
is this your homework assignment for database class?

【在 h******t 的大作中提到】
: how many students participate in the most popular student activity
: what's the name of this actiity
: ACTIVITY (
: actid number ,
: activity_name varchar2(25)
: );
: PARTICIPATES_IN (
: stuid number,
: actid number
: );

avatar
h*t
3

come on, help me, due tomorrow

【在 w*****g 的大作中提到】
: another one? :)
: is this your homework assignment for database class?

avatar
p*y
4
总觉得这种做法不太好.

【在 h******t 的大作中提到】
:
: come on, help me, due tomorrow

avatar
s*i
5
creat view A-N(actid,c)
as select actid, count(*)
from participates_in
group by actid;
select activity_name, Max(c)
from A-N, ACTIVITY
where A-N.actid=activity.actid;

【在 h******t 的大作中提到】
:
: come on, help me, due tomorrow

avatar
h*t
6

不懂就问,有啥不好
不懂装懂不好,太害羞也不好

【在 p*****y 的大作中提到】
: 总觉得这种做法不太好.
avatar
h*t
7
I got in this way, never thought use view
thanks sui
SELECT C1, activity_name
FROM (SELECT COUNT(stuid) C1, activity_name
FROM (SELECT Participates_in.stuid, Activity.activity_name
FROM Participates_in , Activity
WHERE Participates_in.actid=Activity.actid)
GROUP BY activity_name)
WHERE C1= (SELECT MAX(C2) FROM (SELECT COUNT(stuid) C2
FROM Participates_in GROUP BY Participates_in.actid));

【在 s*i 的大作中提到】
: creat view A-N(actid,c)
: as select actid, count(*)
: from participates_in
: group by actid;
: select activity_name, Max(c)
: from A-N, ACTIVITY
: where A-N.actid=activity.actid;

avatar
q*j
8
Is there any requirements to use just one query? "create view" is
considered as one query itself.
If it's homework question, you'd better check the requirement, otherwise,
"create view" is a more intuitive way to do the query.

【在 h******t 的大作中提到】
: I got in this way, never thought use view
: thanks sui
: SELECT C1, activity_name
: FROM (SELECT COUNT(stuid) C1, activity_name
: FROM (SELECT Participates_in.stuid, Activity.activity_name
: FROM Participates_in , Activity
: WHERE Participates_in.actid=Activity.actid)
: GROUP BY activity_name)
: WHERE C1= (SELECT MAX(C2) FROM (SELECT COUNT(stuid) C2
: FROM Participates_in GROUP BY Participates_in.actid));

avatar
s*i
9
I remember we can not embed another SELECT clause in FROM clause!
However, I guess you can JOIN some tables in FROM clause.

【在 h******t 的大作中提到】
: I got in this way, never thought use view
: thanks sui
: SELECT C1, activity_name
: FROM (SELECT COUNT(stuid) C1, activity_name
: FROM (SELECT Participates_in.stuid, Activity.activity_name
: FROM Participates_in , Activity
: WHERE Participates_in.actid=Activity.actid)
: GROUP BY activity_name)
: WHERE C1= (SELECT MAX(C2) FROM (SELECT COUNT(stuid) C2
: FROM Participates_in GROUP BY Participates_in.actid));

avatar
q*j
10
MySQL can't, but other commercial DB can.

【在 s*i 的大作中提到】
: I remember we can not embed another SELECT clause in FROM clause!
: However, I guess you can JOIN some tables in FROM clause.

avatar
s*i
11
I don't even believe ORACLE can.

【在 q*j 的大作中提到】
: MySQL can't, but other commercial DB can.
avatar
h*t
12

I use Oracle, and it works

【在 s*i 的大作中提到】
: I don't even believe ORACLE can.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。