zoukankan      html  css  js  c++  java
  • SQL简单记录

    数据库特性:1.原子性、2.一致性、3.隔离性、4.持久性
    1.use/show/create datebase; 
     
    2.distinct 去重
    例:SELECT DISTINCT country FROM Websites;

    3.分页limit
    select * from 表名 limit start,count
    查询前3行男生信息
    select * from students where gender=1 limit 0,3;

    4.分组group by
    select gender from students group by gender;

    +--------+
    | gender |
    +--------+
    | 男 |
    | 女 |
    | 中性 |
    | 保密 |
    +--------+

    5.连接查询join……on 
    select * from 表1 inner或left或right join 表2 on 表1.列 = 表2.列

    6.排序
    select * from 表名 order by 列1 asc|desc [,列2 asc|desc,...]

    7.优先级

    and比or先运算,如果同时出现并希望先算or,需要结合()使用

    8.自关联

    创建areas表的语句如下:
    create table areas(
    aid int primary key,
    atitle varchar(20),
    pid int
    );
    从sql文件中导入数据
    source areas.sql;
    查询一共有多少个省
    select count(*) from areas where pid is null;

    总结:完整的select语句

    select distinct *
    from 表名
    where ....
    group by ... having ...
    order by ...
    limit start,count

    执行顺序为:
    from 表名
    where ....
    group by ...
    select distinct *
    having ...
    order by ...
    limit start,count

  • 相关阅读:
    Lua 语言学习
    Unity EasyTouch官方案例学习
    Unity Dotween官方案例学习
    斗地主出牌规则
    C# XML文件读取
    斗地主项目总结
    C# 委托和事件
    C# 观察者模式
    消防法及相关法律法规(二)
    消防法及相关法律法规(一)
  • 原文地址:https://www.cnblogs.com/ybxw/p/12531012.html
Copyright © 2011-2022 走看看