--检索
select * from tb_student
select tsname,tsage,tsgender from tb_student
select tsname as '姓名',tsage as '年龄' form tb_student
--起别名
select 名字=tsname,年龄=tsage from tb_student
select 名字=tsname,年龄=tsage from student where tsgender=1
--做计算
select 100+0
--获取时间
select GETDATE()
--获取前十数据
select top 10 * from tb_student
--获取前十的数据并按照年龄排列
select top 5 * from tb_student order by tsage
--获取全部数据的前百分之20并按照年龄从大到小排序
select top 20 percent * from tb_student order by tsage desc
--数据去重
select distinct taname from tb_student
--获取学生数据数量
select COUNT(*) from tb_student
--获取数学分数最大值
select MAX(tsmath),tsenglish from tb_score
--获取数学成绩第一名的学生的数学成绩和英语成绩
select top 1 tsenglish,tsmath from tb_score order by tsmath desc
select tsenglish,tsmath from tb_score tb where tb.tsmath = (select max(tsmath) from tb_score)
select MIN(tsenglish) from tb_score
select SUM(tsenglish) from tb_score
select AVG(tsenglish) from tbscore
--最大值 最小值 平均值 总和 合并到一起显示
select
MAX(tsenglish) as '英语最高成绩',
MIN(tsenglish) as '最低成绩',
SUM(tsenglish) as '总和',
AVG(tsenglish) as '平均成绩'
from tb_score
--统计英语成绩个数(统计时null不参与计算)
select COUNT(tsenglish) from tb_score
网友评论