zoukankan      html  css  js  c++  java
  • MySQL之高级增删改查一

    一、select all/distinct 字段名/别名 from table where条件+【1】+【2】+【3】;

    where条件:>,<,≥,≤,like,between and(闭区间),in ,not in,与&&,或||,非!

    all:查询去全部

    distinct:去掉重复的结果

    【1】:group by 【asc/desc】   asc:升序,desc:降序

    【2】:order by

    【3】:limit           limit 3:取前3条记录;limit 2,3:从第三条记录开始,共取3条记录(从位置2开始,length为3)----可以用来分页

    1、举例演示

    先建一个表,id为主键(primary key),且自增长(auto_increment)

    create table testabc (id int primary key auto_increment,name varchar(4));

    添加数据

    insert into testabc set name='a';

    批量添加

    insert into testabc (name) values ('a'),('b'),('c'),('c'),('a'),('a');

    select * from testabc where name='a';

    select * from testabc group by name;

    限制前3个 select * from testabc limit 3;

    select * from testabc limit 2,3; 从第三条记录开始,共取3条记录(从位置2开始,length为3)

    二、常用函数max(),min(),avg(),count(),count()---记录值为NULL时不统计入数

    1、举例演示,表如下

    select max(age) from stu;

    select sex, count(*) from stu group by sex;

    select sex,count(*),max(age),avg(age) from stu group by sex;

  • 相关阅读:
    排序算法总结
    设计模式---(简单工厂模式,工厂模式,抽象工程模式),单例模式,代理模式,装饰器
    网易编程题——牛牛的闹钟
    Python + sqlalchemy + Pandas + Mysql 实现自动创建表,插入数据
    cucumber
    加油
    重新学习python爬虫
    python 网址
    《高兴》 贾平凹 摘抄
    funny python
  • 原文地址:https://www.cnblogs.com/sunny0/p/8944383.html
Copyright © 2011-2022 走看看