注册 登录
编程论坛 SQL Server论坛

如何使要查询的信息在一表中出现?

isscal 发布于 2010-08-13 16:50, 547 次点击
TABLE1(s_no,s_name,s_sex,birthday,polity)
TABLE2(s_no,c_no,score)
针对这两表查询:
一、所有学生的姓名、年龄、选修课程、成绩(一张表上同时出现以上信息)
二、按性别分组查询男女生的平均成绩。
谢谢!
2 回复
#2
aei1352010-08-13 22:18
你那表没年龄啊?
一.select table1.s_name,table2.c_no,table2.score from table1 left join table2 on table1.s_no=table2.s_no

二.select table1.s_sex,avg(isnull(score,0)) avgscore from table2 right join table1 on table1.s_no=table2.s_no
group by table1.s_sex
#3
cnfarer2010-08-13 22:27
年龄可以算出来的
1