第一期:
学生表(学生id,姓名,性别,分数) )student(s_id, name, sex, score)
班级表(班级id,班级名称) class(c_id, c_name)
学生班级表(班级id,学生id) student_class(s_id,c_id)
1.查询一班得分在80分以上或者等于60,61,62的学生
2.査询所有班级的名称,和所有版中女生人数和女生的平均分。
答案:
(1)SELECT s.s_id,s.name,s.score,sc.c_id,c.c_name from student s
LEFT JOIN student_class sc on s.s_id = sc.s_id
LEFT JOIN class c on sc.c_id=c.c_id
where (s.score>80 or s.score in(60,61,62)) and c.c_name='一班';
(2)SELECT sc.s_id,c.c_name,COUNT(s.sex),AVG(s.score) from student_class sc
LEFT JOIN class c on sc.c_id=c.c_id
LEFT JOIN student s on sc.s_id = s.s_id
where s.sex='女' group BY c.c_name ORDER BY c.c_id asc;
返回记录的条数:
法一:SELECT * FROM Persons LIMIT 5
法二:SELECT * FROM Persons rownum <= 5
法三:SELECT TOP 5 * FROM Persons
通配符
''' SELECT * FROM Persons WHERE City LIKE 'N%' N开头
SELECT * FROM Persons WHERE City LIKE '%g' g结尾
SELECT * FROM Persons WHERE City LIKE '%lon%' 中间含lon
SELECT * FROM Persons WHERE City NOT LIKE '%lon%' 不含lon
SELECT * FROM Persons WHERE FirstName LIKE '_eorge' 第一个字符之后是 "eorge"
SELECT * FROM Persons WHERE LastName LIKE 'C_r_er'
姓氏以 "C" 开头,然后是一个任意字符,然后是 "r",然后是任意字符,然后是 "er"
SELECT * FROM Persons WHERE City LIKE '[ALN]%' 以 "A" 或 "L" 或 "N" 开头的人
SELECT * FROM Persons WHERE City LIKE '[!ALN]%' 不以 "A" 或 "L" 或 "N" 开头的人:
SELECT * FROM Persons WHERE City LIKE '[^ALN]%' 不以 "A" 或 "L" 或 "N" 开头的
'''