数据库学习笔记(十二)

来源:互联网 发布:java 悲观锁 编辑:程序博客网 时间:2024/05/22 16:01
--查询
select *  from student where sex = '女'


select courseno, cname, credit
from course




select studentno , sname, phone
FROM student
WHERE point > 780


select studentno, sname, phone, classname
FROM student as 学生, class as 班级
WHERE point > 780 and 班级.classno = 学生.classno


select studentno, courseno, usually, final
FROM score
WHERE (courseno = 'c05109' OR courseno = 'c06108') AND final >= 85  


update test01.dbo.奖学金 
SET  奖学金 = null
WHERE 奖学金 = null
SELECT 学号, 班级编号, 综合评测, 班级名词
FROM 奖学金
WHERE 奖学金 is NOT NULL






--比较运算符
SELECt studentno, sname, point, Email
FROM student
WHERE YEAR(birthday) > 1989






--显示手机号开始前三位不是131的
select sname, phone, Email
FROM student
WHERE phone not LIKE '131%'


--查询出生日期在1989年以后出生的学生的学号
select studentno as '学号', sname as '姓名', phone aS '手机号', YEAR(GETDATE() - YEAR(birthday)) as '年龄'
FROM student
WHERE year(birthday) > 1989


--ORDER BY排序
select studentno, sname, point as '入学成绩'
FROM student 
ORDER BY point desc


--消除重行的
select DISTINCT studentno, sname
FROM teach_class
WHERE final > 85
ORDER BY sname  




--TOP n输出
select TOP 5 studentno, sname, point, phone
FROM student
order by point desc






select TOP 35 percent studentno studentno, sname, point, phone
FROM student
order BY point desc






--group by && having
select studentno, sum(usually * 0.3 + final * 0.7) as '总分'
FROM score
where final > 75
GROUP BY studentno
having COUNT(*) >= 3
order by sum(usually * 0.3 + final *0.7) desc




select studentno, birthday, phone
FROM student
WHERE point > 788
order by birthday
compute MAX(birthday)












  
0 0
原创粉丝点击