SQL-server简单知识总结

as(重命名)

设计的书库库中用的字段名通常是英文字符,为了清楚的表达出来 as 将列名重新命名(但是数据库里的列名不会改变)
select readerID as ‘借书证号’ from borrow

in(集合)

筛选出集合里的数据的时候用到in
select ‘信息系当前借书的人数:’, distinct readerID
from borrow where readID in (
select readerID
from reader where readerDepartment=’信息系’
)

简单函数进行运算:

(1) sum(列名) 求筛选出来的数据求和
(2) max(列名) 求筛选出来的数据查找最大值
(3) min(列名) 求筛选出来的数据查找最小值
(4) count(列名) 求筛选出来的数量
(5) avg(列名)  求筛选出来的平均值

into table(将求筛选出来的数据存入一个表中)

select id,name,score into 1601_score from final_score where class='1601'

此时会建立一个新表,将id name score 存放在新建表中的1601_score

top(筛选出顶部的多少数据)

select top 1000 id,name,score into Top_score from final_score order by score desc
将前1000名的学生进行临时存储

左去空格:ltri(列名),右去空格:rtrim(列名)

类型的转换(例如将date类型转换成varchar类型)+ 字符段的截取substring()

(1)convert(varchar(30),birthday,21)
表示的是将birthday这个字符段下的数据转化成varchar类型,并以第21类形式展现出来

(2)substring(截取的字符段,截取的开始位置,截取的长度)
    例如birthday下的1999-06-12,将其的出生的月份找出来
    substring(birthday,6,2);
Fork me on GitHub