当前位置:Gxlcms > 数据库问题 > sql回顾而知新

sql回顾而知新

时间:2021-07-01 10:21:17 帮助过:2人阅读

        取值约束,    age int check (age>=10 and age<20)

++++++++++++++++++++++++++++++++++++++++++++++++++++

3.操作语言:

           部分插入    insert  T_stu(f_name,f_sex) values(‘马云‘,‘男‘)

            全部插入  insert T_stu values(25,‘电气‘,‘马云‘,‘男‘,2001-11-14)

           删除: delete from T_stu where name=‘马云‘

           删除记录: truncate table student

           更改: update T_stu set name=‘马玉华‘ where name=‘马云‘

++++++++++++++++++++++++++++++++++++++++++++++++++++

4.基本查询

       select  list_xx  into new_table

    from T_xx, T_XXX  可以是一个表或者是多个表

   where 条件  group by 列名 必须是 前面会出现的 

                      having 已经分组的 表 又加 条件必须 组列中 的一个

 order by XX asc/desc 就是根据 其 排序   

++++++++++++++++++++++++++++++++

   *** select * from teacher age>40

     where DName in (‘计算机‘,‘电气‘)

   **** CName like ‘%气‘

                 _ 表示一个 字符

                  __表示 两个   like‘ [计电]’ 就是 只要 有 任意的一个 字出现就行 

+++++++++++++++++++++++++++++++

5.聚合函数

    通常要和 分组命令 一起使用

      1.选中的 列的 总数        sum(sal) as 工资总数 from  teacher where age>40

       2. 列中值得 个数     count(*) from teacher where sex=‘女‘--所有女教师的人数

       3.某一列中 的 最大 最小  max(age)from TT where sex=‘男‘

          年龄最大 男 教师的  信息

               select * from teacher where age=(select max(age) from TT where sex=‘男‘)

        4. 平均年龄的 avg(age)   

++++++++++++++++++++++++++++++++++++++++++++++

 

sql回顾而知新

标签:

人气教程排行