• mysql_表内容_操作


    1、增

    语法:insert into 表 (列名,列名...) values (值,值...)

    # 插入单条数据
            insert into 表 (列名,列名...) values (值,值...)
    

    # 插入多条数据
           insert into 表 (列名,列名...) values (值,值...),(值,值...)

    # 插入另一条语句的查询结果
            insert into 表 (列名,列名...) select 列名,... from

    2、删

    语法:delete from 表

    delete from 表;
    delete fromwhere id=1;

    3、改

    语法:update 表 set name = 'nick' where id>1

    update 表 set name = 'nick' where id>1

    4、查

    语法:select * from 表

    select * fromselect * fromwhere id > 1
    select nid,name,gender as gg fromwhere id > 1
    
    # as 做别名

    5、条件

    语法:select * from 表 where id > 1

        select * fromwhere id > 1 and name != 'nick' and num = 12;    # 多个条件
        select * fromwhere id between 5 and 16;                       # id在5到16之间
        select * fromwhere id in (11,22,33);                          # id在元祖中
        select * fromwhere id not in (11,22,33);                      # id不在元祖中
        select * fromwhere id in (select nid from 表);                # id在查询结果中

    6、通配符

     语法:select * from 表 where name like '_n%'

      select * fromwhere name like 'ni%'  # ni开头的所有(多个字符串)
        select * fromwhere name like 's_'   # s开头的所有(一个字符)

    7、限制

    语法:select * from 表 limit 9,5;

        select * from 表 limit 5;            # 前5行
        select * from 表 limit 9,5;          # 从第9行开始的5行
        select * from 表 limit 5 offset 9    # 从第9行开始的5行

    8、排序

    语法:select * from 表 order by 列1 desc,列2 asc

        select * from 表 order by 列 asc             # 根据 “列” 从小到大排列
        select * from 表 order by 列 desc            # 根据 “列” 从大到小排列
        select * from 表 order by 列1 desc,列2 asc   # 根据 “列1” 从大到小排列,如果相同则按列2从小到大排序

    9、分组

    语法:select num from 表 group by num

        select num from 表 group by num           # 根据num分组
        select num,nid from 表 group by num,nid   # 根据num和nid分组
        select num,nid from 表  where nid > 10 group by num,nid order nid desc
        select num,nid,count(*),sum(score),max(score),min(score) from 表 group by num,nid  # 内置函数
        select num from 表 group by num having max(id) > 10    # 前面计算的结果交由后面处理
     
        注:group by 必须在where之后,order by之前
    count(*)、count(1) # 表示个数
    sum(score)        # 表示和
    max(score)        # 表示最大数
    min(score)        # 表示最小数
    
    having            # 要用前面处理结果是用having。

    10、连表

    语法:inner join . onleft join . onright join . on

        无对应关系则不显示
        select A.num, A.name, B.name
        from A,B
        Where A.nid = B.nid
     
        无对应关系则不显示
        select A.num, A.name, B.name
        from A inner join B
        on A.nid = B.nid
     
        A表所有显示,如果B中无对应关系,则值为null
        select A.num, A.name, B.name
        from A left join B
        on A.nid = B.nid
     
        B表所有显示,如果B中无对应关系,则值为null
        select A.num, A.name, B.name
        from A right join B
        on A.nid = B.nid

    11、组合

    语法:union、union all
    
        组合,自动处理重合
        select nickname
        from A
        union
        select name
        from B
     
        组合,不处理重合
        select nickname
        from A
        union all
        select name
        from B

    参考:https://www.cnblogs.com/suoning/articles/5769141.html

  • 相关阅读:
    基于物品属性的过滤
    第一个极小的机器学习的应用
    基于物品过滤的Slope One 算法
    【转】Python爬虫(1)_基本原理
    程序猿面试题集锦
    Django:popup弹出框简单应用实例
    【转】Python max内置函数详细介绍
    MySQL数据库(9)_MySQL数据库常用操作命令
    【转】Python的hasattr() getattr() setattr() 函数使用方法详解
    Git常用命令
  • 原文地址:https://www.cnblogs.com/cui0x01/p/8640766.html
Copyright © 2020-2023  润新知