简单查询

SQL的增删改查:

  一、添加数据, insert into 表名 values(添加的内容)  ,添加的内容每项用逗号隔开,注意事项:

    字符串和字符需要加单引号,布尔型添加0或1不带引号

    datetime类型按照格式 '2018-01-02 11:34:45'来添加,也要加单引号

    整数型,小数型不用加引号

    表里有几列就要添加几个数据,如果有空数据,则要指定添加数据的列 insert into 表名(要添加数据的列) values() 

    SQL语句里不区分大小写

    自增长列添加数据直接给0,会自动增长

  二、修改数据

    update 表名 set 列名=修改的值 where 可以锁定需要修改项的条件

  三、删除数据

    delete from 表名 where 要删除数据的锁定条件

简单查询
1查询所有数据
selete * from info
2查询指定列
select code,name from info
3给列指定名称
select code as '代号',name as '姓名' from info
4条件查询
select * from info where code='p001'
5模糊查询:根据关键字查询
select * from car where name like '_奥迪_' %百分号奥迪前面可以有N个字符,可以后面有N个字符;_下滑线只能出现一个字符,
6排序查询
select * from car order by price desc,oil desc
代表以价格进行排序,price后面不加,默认升序排列,降序使用desc;price是第一优先级排序,如果价格相等则oil排序
7去重查询
select distinct brand from car
8分页查询
select * from car limit 5,5
跳过几条,取几条
9统计查询或聚合函数
select count(*) from car查询出多少条数据
取最大值
select max(price) from car
取最小值
select min(price) from car
取平均值
select avg(price) from car
分组查询
select brand,count(*) from car group by brand
select brand from car group by brand having count(*)>=3
范围查询
select * from car where price>=40 and price<=60
select * from car where price between 40 and 60
离散查询
select * from car where price in(10,20,30,40)在里面出现
select * from car where price not in(10,20,30,40)不在里面出现
联合查询
union
连接查询
形成笛卡尔积

 

posted @ 2018-01-02 08:35  FTHeD  阅读(123)  评论(0编辑  收藏  举报