数据库增添

条件查询用where

比如:查询Score表中成绩在60到80之间的所有记录。

select DEGREE from score where degree>60 and degree<80

模糊查询用%

比如查询与三相关的数据:

 where cno like '3%'   3%是已三开头   %3%是中间带3  %3是末尾带3

排序查询 order  by desc降序  asc升序   去重查询 distinct 

分组查询group by   联合查询union

 子查询 :

查询Score表中的最高分的学生学号和课程号。(子查询或者排序)
select* from score where degree in (select MAX(degree)from score)

聚合函数: max()  min()  avg() count() sum() 

数学函数:ceiling()  floor() round(字段名,小数位)

abs()  pi()

字符串函数:lower() upper() trim() replace(源字段,查找字符)

substring(源字段,索引位置)

转换函数 + 运算,拼接

convert(类型,字段)

cast(字段 as类型)

时间日期函数:

getdate : year(getdate())

dateadd(增加类型,增加量,数据源,dateadd(month,7,getdate())

datename(日期类型,数据源),datename(day,getdate())

原文地址:https://www.cnblogs.com/yujiamin123/p/7060374.html