select sname,avg(grade) from sc,student wherestudent.sno=sc.sno 这句话有没有错,求grade的平均值

selectsname,avg(grade)fromsc,studentwherestudent.sno=sc.sno这句话有没有错,求grade的平均值... select sname,avg(grade) from sc,student wherestudent.sno=sc.sno
这句话有没有错,求grade的平均值
展开
 我来答
yixiaxi663
2011-09-21 · TA获得超过3.1万个赞
知道大有可为答主
回答量:2.5万
采纳率:0%
帮助的人:1.4亿
展开全部
SQL是一种结构化查询语言即Structure Query Language

一般格式:
SELECT[DISTINCT]<目标列表达式>…
FROM<表名>,<查询名>……
[WHERE <条件表达式>]
[GROUP BY<列名1>[HAVING<条件表达式>]
[ORDER BY<列名2>[ASC│DESC];
SELECT SNAME,SDEPT FROM STUDENT

SELECT SNO,CNO FROM 查询1
SELECT * FROM STUDENT
SELECT DISTINCT SNO FROM SC
SELECT SNAME,SAGE FROM STUDENT WHERE SDEPT='CS'
WHERE SAGE NOT BETWEEN 10 AND 18
'',"";
BETWEEN #1978-01-01# AND #1980-12-31#
*,?,#
'' ""
IN NOT IN
WHERE SDEPT IN('CS','IS'); SDEPT='CS' OR SEPT='IS'
LIKE *,?,#
SELECT * FROM STUDENT WHERE SNAME LIKE '刘?'
SAGE LIKE '1#'
1按学生成绩降序排序,成绩相同按课程号排序
select * from sc order by grade desc,cno
2安课程号排序,课程号相同按成绩将需排列

IS NULL,IS NOT NULL
SELECT SNO,CNO FROM SC WHERE GRADE IS NULL
count(*),count(CNO),sum(),avg(),min(),max()
select count(*) from sc
select cno,count(*) from sc group by cno
and or not
select sname ,2003-sage as 出生年份 from student
SELECT SC.SNO,SNAME,CNO FROM STUDENT,SC WHERE STUDENT.SNO=SC.SNO
SELECT C1.CNO,C2.CPNO FROM COURSE C1,COURSE C2 WHERE C1.CPNO=C2.CNO
LEFT JOIN RIGHT JOIN
SELECT course.*, sc.*
FROM course LEFT JOIN sc ON course.cno = sc.cno;
SELECT SNAME+SDEPT AS SNSD FROM STUDENT
1查询信息系年龄在18到20之间的学生信息
SELECT *
FROM STUDENT
WHERE SDEPT='IS'AND SAGE BETWEEN 18 AND 20;
2查询每门课程相应的选课人数
SELECT CNO,COUNT(SNO)
FROM SC
GROUP BY CNO;
SELECT COUNT(*) FROM SC
3查询每个学生不及格课程门数
SELECT CNO,COUNT(CNO)
FROM SC
WHERE GRADE<60
GROUP BY SNO
4查询成绩在90到100份之间的每门课程的选修人数
SELECT CNO, COUNT( SNO)
FROM SC
WHERE GRADE BETWEEN 90 AND 100
GROUP BY CNO ;
5查询姓名第二个字是“力”的学生姓名和所在系
SELECT SNAME,SDEPT
FROM STUDENT
WHERE SNAME LIKE "?力*";
6查询没有成绩的学生学号和对应的课程号
SELECT SNO,CNO
FROM SC
WHERE GRADE IS NULL;
7查询数学系和信息系所有男学生的情况
SELECT *
FROM STUDENT
WHERE SDEPT ="IS" OR SDEPT= "MA" AND SSEX="男";

8查询总成绩大于200分的学生学号
SELECT SNO
FROM SC
GROUP BY SNO HAVING SUM(GRADE)>200;
SELECT * FROM SC ORDER BY SNO ,GRADE DESC

1.SELECT ENO,ENAME FROM EMP,WORKS WHERE
CMP.ENO=WORKS.ENO,SEX='男',AGE>50
2.SELECT ENO,ENAME FROM EMP ,WORKS WHERE SALARY>1000 AND EMP.ENO=WORKS.ENO
3.SELECT ENO,ENAME FROM EMP,COMP,WORKS WHERE CNAME="LHGS" AND WORKS.CNO=COMP.CNO AND EMP.ENO=WORKS.ENO
4.SELECT ENO,ENAME FROM EMP,COMP,WORKS WHERE WORKS.CNO=COMP.CNO AND EMP.ENO=WORKS.ENO AND SEX='M'AND CNAME='LHGS' AND SALARY>1000
left join right jion
select * from student left join sc on studnt.sno=sc.sno

#1987-10-01#
1、select distinct sno from sc where grade<60
2 select * from student where sdept in('cs','is')
select * from student where sdept='cs' or sdept='is'
3 select sno,sname,sage from student where sage between 10 and 19
>=10 and <=19
like '1#'
4 select sname ,sdept from student where sname like '?力*'
5 select sno from sc where grade is not null
子查询
概念:
分类:
引导谓词:select from where sage>(select sage from student where sdept='cs')
>,=,<
查询和刘晨同在一个系学习的学生
SELECT S1.* FROM STUDENT S1,STUDENT S2 WHERE S2.SNAME='刘晨' AND S1.SDEPT=S2.SDEPT
SELECT *
FROM STUDENT
WHERE SDEPT=
(SELECT SDEPT
FROM STUDENT
WHERE SNAME='刘晨')
select sname from student where sdept=(select sdept from student where sname='刘晨')

in
查询选修了数据库课程的学生的姓名和所在系
SELECT SNAME,SDEPT
FROM STUDENT
WHERE SNO IN
( SELECT SNO
FROM SC
WHERE CNO IN
(SELECT CNO
FROM COURSE
WHERE CNAME='数据库'))
select sname ,sdept
from student
where sno in
(select sno
from sc
where cno=
(select cno
from course
where cname='数据库'))
select sname ,sdept
from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno and cname='数据库'
查询其他系比信息系任一学生年龄小的学生情况
any,all
>any大于子查询结果中的某个值(>min()大于最小值)
>all大于子查询结果中的所有值(>max()大于最大值)
<any小于子查询结果中的某个值(<max()小于最大值)
<all小于子查询结果中的所有值(<min()小于最小值)
SELECT *
FROM STUDENT
WHERE SAGE<(SELECT max(SAGE)
FROM STUDENT WHERE SDEPT='IS')
AND SDEPT<>'IS'

select sname
from student
where sage <any(select sage from student where sdept='is') and sdept <>'is'
集合查询
并(UNION)、交、差
查询既选修了1号课程又选修了2号课程的学生学号。
SELECT SNO FROM SC WHERE CNO=1 AND SNO IN(SELECT SNO FROM SC WHERE CNO=2)

exists
网络班
查询选修了全部课程的学生姓名
select sname
from student
where sno in
(select sno
from sc
group by sno having count(*)=
(select count(*)
from course) )
使用EXISTS
SELECT SNAME
FROM STUDENT
WHERE NOT EXISTS
(SELECT *
FROM COURSE
WHERE NOT EXISTS
(SELECT *
FROM SC
WHERE SNO=STUDENT.SNO
AND CNO=COURSE.CNO))

查询至少选修了01001选修的全部课程的学生号码
select sno from sc where cno in(select cno from sc where sno=01001) group by sno having count(*)=(select count(*) from sc where sno=01001)

SELECT SNAME FROM STUDENT
WHERE SNO IN(SELECT SNO FROM SC WHERE CNO IN(SELECT CNO FROM COURSE WHERE CNAME='数据库'))

更新查询
插入(INSERT INTO)
INSERT INTO STUDENT VALUES(95033,'','IS','男',19)
INSERT INTO C1(CPNO,CNAME)
SELECT CPNO,CNAME FROM COURSE WHERE CNO IN(1,2)
INSERT INTO SC1(SNO,CNO)
SELECT SNO,CNO FROM STUDENT,COURSE
修改(UPDATE)
UPDATE SC SET GRADE=0 WHERE 'IS'=(SELECT SDEPT FROM STUDENT WHERE SNO=SC.SNO )
删除(DELETE)
DELETE FROM C1
DELETE FROM SC WHERE 'IS' =(SELECT SDEPT FROM STUDENT WHERE SNO=SC.SNO)

UPDATE STUDENT SET SNO=95030 WHERE SNO=95004
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式