• mysql学习总结(二)


    1.索引

           唯一索引和联合唯一索引

              唯一索引:unique(列名) :有添加unique关键字的列名在列名下的数据不会重复,添加unique关键字的列表能够提高查询效率

             联合唯一索引: unique(列名1,列名2,....) 特性是在括号内存在多个列名,它的规则是同表下不能出现相同的一行数据,可以用来建立多对多的数据表

           增:

             copy数据的sql语句:insert into 表名(列名) select 列名 from 另一个表名;

           删:

               delete from 表名 where id =表id and / or   name='xxxxxx';根据条件删除数据

          改:

                 update 表名 set name='xxxxx',age='xxxxx'  where  id =表id;

        查询:(重点)

                  1.闭区间查询

                            select * from 表名  where id  between 9 and 35; 查询id 9到35之间的数据 

                  2.通配符查询:

                               select * from 表名 name like '李%';

                  3.排序查询

                          降序: select * from 表名 order by 列名  desc; 

                          升序: select*from 表名 order by 列名  asc;

                           多列升序降序: select * from 表名 order by 列名 desc, 列名 asc;

                   4.分组查询:把一组中相同的数据进行排序

                      select age, count(num) from 表名 as 别名 group by age; 

                     select age,count(num) as cnt from 表名 group by age  having cnt >1;

                        having的=实现二次查询;

                       where 和having的区别:

                               1.having与where类似,可以筛选数据

                                2.where针对表中的列表发会作用,查询数据

                                3.having针对查询结果中的列表发挥作用,二次筛选数据,和group by 配合使用

                  5.分页查询:

                             select * from 表名 limit (page-1)*offset, offset;

                 6.连表操作:

                             左连接:

                                   select * from 表1 left join 表2 on 表1.id=表2.id;

                             右连接:

                                   select * from 表1 right join 表2  on 表1.id=表2.id

                            内连接:

                                       select * friom 表1 inner join 表2  on 表1.id=表2.id;

    查询顺序:

          select name,sum(score) from 表     

                  1.where id > 10   

                  2.group by    score 

                  3.having     age> 12     

                  4.order by age   desc

                  5.limit 2, 10 

  • 相关阅读:
    程序员保持快乐活跃的6个好习惯(转)
    Spring MVC Hello World Example(转)
    Oracle定时执行存储过程(转)
    各种常见数据库分页实现(转)
    Linux SSH常用总结(转)
    让人深思......
    void及void指针含义的深刻解析
    UVa 11988
    网络编程学习小结
    Deep Learning(深度学习) 学习笔记(四)
  • 原文地址:https://www.cnblogs.com/xzcvblogs/p/11019587.html
Copyright © 2020-2023  润新知