• 数据库 --- 3 行(记录)操作 单表查询


    一.插入数据  inset

      ①  insert into 表名(字段1,字段2,...)values(值1,值2,...);

       指定字段插入数据,插入的值要和你之前的字段相匹配

      ②  insert  into 表名  values (值1,值2,....);

       不指定字段时,就按照默认的几个字段来插入数据

      ③插入多条记录(用逗号分隔)

       insert into 表名 values

          (值1,值2,....),

          (值1,值2,....),

          (值1,值2,....);

      ④将查询结果插入新表(字段要对应好)

        insert into 表名(字段1,字段2,.....)

            select  (字段1,字段2,.....)  from  表2

            where .....;

    二. 更新(修改)数据    update

      update  表名 set 

        字段1 = 值1,

        字段2 = 值2,

        where ......;    (条件限制)

    三 . 删除数据      delete

      ①delete  from  表名

          where  .....; (根据条件删除)

      ②  delete  from  表名;

        清空表  但不彻底  auto_increment  项,会继续增加

      ③  truncate  table 表名;

        清空表   彻底清除,从1 重新开始

    四.单表查询

      concat( )  函数用于连接字符串

      1.语法:

       select  distinct 字段1,字段2,...  from  表名(或者 库名.表名)

             (distinct  去重)

           where  条件      (查询条件)

           group by  字段        (分组)

           having   条件      (筛选,再对分组后的数据限制)

           order by 字段       排序(默认为升序)

           limet   数1,数2     从 数1 开始查   共查出 数2 条

      2.优先级:

      3. where 约束

      4.group by(和聚合函数一起使用) 

       select post,count(id) as count from employee 

          group by post;

        按岗位分组  ,count 查看每组有多少人

      5.聚合函数

      6.having   过滤

      实例:

        select post,avg(salary) as new_sa from employee

            where age>=30

            group by post

            having avg(salary) > 10000;

      7. 去重  distinct 

       select  distinct post from employee;

          去重要写在查询字段的前面 

      8.  排序   order by

      9.查询条数   limit

      10.  使用正则表达式 查询

       

  • 相关阅读:
    Symbol
    对象的附加属性
    怪异盒模型
    javascript的三大组成部分
    让目标对象滚动到视口位置
    隐藏单个盒子的滚动条
    uni-app判断有没有安装这个app,如果有的话直接打开,没有的话跳转到下载页面
    js 读取json文件
    openlays 使用 svg标注,动态修改svg颜色
    iview table组件内容过多用“...”代替,鼠标悬停显示全部内容
  • 原文地址:https://www.cnblogs.com/sc-1067178406/p/10283354.html
Copyright © 2020-2023  润新知