数据库常用的函数:

1.平均值:AVG ()函数返回数值列的平均值。

2. TOP 子句用于规定要返回的记录的数目。

   如:select top 3 *from StudentInfo

        select top 3 sName from StudentInfo

3.   --order by 排序     例:select *from StudentInfo 

          order by cid desc

4.---distinct用于返回唯一不同的值。

         例:select distinct sGender from StudentInfo

5.--where 查询

    例:  select *from StudentInfo 

             where cid>=2

6.-----between--and---

    例: select *from ScoreInfo

           where sId between 5 and 10

7.----in操作符的使用 ---in(值1,值2,值3....)

    例:select *from ScoreInfo

          where stuId in(1,3,5)

8.-------模糊查询---(%和_)

      例 :select *from StudentInfo

            where sName like '_志_'    ,指的是查询名字中第二个字是 '志' 的人

           where sName like '%志'      ,指的是查询名字中最后一个字是 '志' 的人

9.---左连接:两个表中完全匹配的数据,左表特有的数据 

    例:  select *from ClassInfo as ci

            left join StudentInfo as si on
           si.cid=ci.cId

   --右连接: 两个表中完全匹配的数据,右表特有的数据

           例:  select *from ClassInfo  as  ci

                    right join StudentInfo as  si  on
                    si.cid=ci.cId

 

10. --count() 函数----记录数目

    例: select  *from  StudentInfo

            select   count(sName)  as  姓名  from StudentInfo

11.---min()  计算最小值

     例:select  *from  ScoreInfo

            select min([scoreValue])  as  最低成绩  from ScoreInfo

12.---max()  计算最大值

13.--having 用来进行分组后的筛选,用在group by 之后
     -----select 后面的列必须包含在聚合函数中,having中不能使用未参与分组的列

    

14.--MID 函数用于从文本字段中提取字符。

     

 

    

 

  

 

posted @ 2017-10-31 17:35  枫叶少年  阅读(1082)  评论(0)    收藏  举报