<数据库>MySQL补充

    show create table 表名 \G;(查看创建的属性)
    alter table 表名 auto_increment=xx;(修改自增起始值)
    set session auto_increment_offset=xx;(修改步长)
    索引的目的:加速查找
    约束:
        主键
        外键
        唯一索引:unique 名字 (列名) ----不允许重复(可以为空)
        联合唯一:unique 名字 (列名1,列名2)---不允许一起重复

    sql语句补充
    select * from 表名;
    select 列名 as 别名 from 表名 where 条件;
    select 列名 as 别名,数字 from 表名 where 条件;(加额外的数字列)
    
    select * from 表名 where 列名 != x;(不等于)
    select * from 表名 where 列名 in (x,y,z);(in(在):x,y,z)
    select * from 表名 where 列名 not in (x,y,z);(不在)
    select * from 表1名 where 列名 in (select 列名 from 表2);(和表2中相同的)
    select * from 表名 where 列名 between x and y; (介于x-y,包含边界)   
    
    select * from 表名 where 列名 like "a%";(%代表所有的值,数量:0-无限多)
    select * from 表名 where 列名 like "a_";(_代表所有的值,数据1个)
    
    select * from 表名 limit x;(前x条)
    
    select * from 表名 limit x,y;(起始位置从x起,往后取y条)
    
    select * from 表名 order by 列名 desc; #大到小
    select * from 表名 order by 列名 asc;  #小到大
    select * from 表名 order by 列名1 desc,列名2 desc;分开排序
    取后y条数据(先排序在取值)
    select * from 表名 order by 列名 desc limit y;  
    分组:
    select count(列名),max(列名),part_id from 表名 group by 列名;(sum:求和,avg:求平均值)
    连表:
    select * from 表1,表2 where 条件;

  select * from 表1 left join 表2 on 列1=列2;

猜你喜欢

转载自www.cnblogs.com/shuimohei/p/10260520.html
今日推荐