Êý¾Ý¿âSQL²éѯÓï¾äÈçÏ£º
create view grade_student(ѧºÅ,ÐÕÃû,Ñ¡¿ÎÃÅÊý,ƽ¾ù·Ö,×î¸ß·Ö,×îµÍ·Ö)
as
select sc.sno,sname,count(cno),avg(grade),max(grade),min(grade)
from sc,student
where student.sno=sc.sno
group by sname,sc.sno
ÎÊÌ⣺
ÔÚ×îºóµÄGROUP BY Óï¾ä¼ÓÉÏ·âºÅ£¨;£©×÷ΪÓï¾äÍê½á Ϊʲô¾Í²»ÄÜÔËÐÐÁË ²»¼ÓÈ´¿ÉÒÔ
ÉèÖÃÎÊÌ⣿
¼ÓÉÏ;ÊÇ¿ÉÒÔµÄàÞ
SQL code:
'¿ÉÒÔÔËÐа¡...'
if object_id('tb')is not null drop table tb
if object_id('test')is not null drop view test
go
create table tb
(
id int,
date datetime
)
go
alter table tb add default getdate() for date
go
insert into tb(id) select 1
union all select 3
union all select 2
union all select 4
go
create view test
as
select id,date=max(date) from tb
group by id;
go
select * from test
/*
id date
---------------------------------
1 2010-04-26 12:42:53.827
2 2010-04-26 12:42:53.827
3 2010-04-26 12:42:53.827
4 2010-04-26 12:42:53.827
*/
Äã²»»áÿ¾ä¶¼¼Ó°É Ö±½ÓÊÇ¿ÉÒÔµÄ
sql server²»ÓÃ¼Ó £»
ÇëÇл»ÊäÈë·¨
create view grade_student(ѧºÅ,ÐÕÃû,Ñ¡¿ÎÃÅÊý,ƽ¾ù·Ö,×î¸ß·Ö,×îµÍ·Ö)
as
select sc.sno,sname,count(cno),avg(grade),max(grade),min(grade)
from sc,student
where student.sno=sc.sno
group by sname,sc.sno
--><