数据库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 语句加上封号(;)作为语句完结 为什么就不能运行了 不加却可以
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 语句加上封号(;)作为语句完结 为什么就不能运行了 不加却可以
if object_id('tb')is not null drop table tb
if object_id('test')is not null drop view test
gocreate table tb
(
id int,
date datetime
)
goalter table tb add default getdate() for date
goinsert into tb(id) select 1
union all select 3
union all select 2
union all select 4
gocreate 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
*/
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
-->不用加;另外去掉(学号,姓名,选课门数,平均分,最高分,最低分)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
服务器: 消息 170,级别 15,状态 1,过程 grade_student,行 6
第 6 行: ';' 附近有语法错误。
像别的SQL语句后面加上;是可以的 GROUP BY不行?
as
select * from sys.objects;
go
select * from dbo.vw_m;
select * from dbo.vw_m;
select * from dbo.vw_m;
select * from dbo.vw_m;
select object_id from dbo.vw_m group by object_id;
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;
如果大家不信就把上面的COPY到自己查询分析器上试能运行不