• mysql 数据的操作


    数据的操作

    指定指端写

       insert into t1(username,hobby) values ('杨得港','上课,写作业,考试');

      insert   into   t2(id,username)   select   id,username  from  t1;

    删 

    delete   from   表 ;   直接删除表里面的所有信息

    delete    from   表   条件;    删除表里面的某一行。   注意下次插入数据的时候,id还是接着写。

        会清空表是不会清空自增字段的offset(偏移量)值

        truncate   table   表;

        会清空表和自增字段的偏移量

    删除某一条数据必须带条件

          delete   from  表   where   条件;

        update   表   set    字段=值   where  条件;    修改一项

        update   表    set    字段=值,字段=值     where   条件;     修改多条数据

    select   id,emp_name    from   employee;

    select  语句

    select     *    from   表;

    select    字段,....     from     表;

    select     字段   as   新名字      from   表;

    select     字段   新名字,   from    表;

    可以更改显示的名称    select   id   as  i,emp_name  as    name   from    employee;

              select    id  i,emp_name   name    from   employee;

    查询后去掉重复的值

    select    distinct   post   from   表名;

    select    distinct    age,gender    from    表名;      只有年龄和性别都一样才会去掉。

    四则预算:

    select    emp_name,salary*12  from   表名;

    select emp_name,salary*12 price from employee;

    concat函数:   做拼接用

    select  concat(emp_name,':',salary')    from   表名;

    concat_ws(':',字段,字段)    from   表名;     表示用:分割字符串

    CASE语句   就相当于条件语句  if  函数       case   when   语句   相当于if条件语句

    select (
    case
    when emp_name='jingliyang' then
    emp_name
    when emp_name='alex' then
    concat(emp_name,'_BIGSB')
    else
    concat(emp_name,'SB')
    end
    ) as new_name
    from employee;

      单表查询

      多表查询

  • 相关阅读:
    ARM中断(一)
    窗口置顶小工具
    volatile关键字
    IIC总线
    ARM中断(三)
    BootLoader —— S3C2440
    视频那些事
    [轉]簡單的顯示隱藏實現
    Apache Service Monitor Start按鈕变灰 的解决方法
    [转载]经典java转码程序,实现native2ascii命令行的功能
  • 原文地址:https://www.cnblogs.com/ch2020/p/12894287.html
Copyright © 2020-2023  润新知