基础单表sql语句

基础增删改查:

新增:

insect in 表名 valuse(字段名1,字段名2,...)

删除:

deldete from 表名 where 条件

修改:

update 表名 set 字段名1 = 新值,字段名2 = 新值, ... where 条件

查询:

select * form 表名;
select * form 表名 where 条件;

条件查询

升降序排列:

-- 升序排列
select * form 表名 order by 字段名
select * form 表名 order by 字段名 asc
-- 降序排列
select * form 表名 order by 字段名 desc

分页查询:

-- 值1 = (页数-1)*值2     值2 = 每一页数据的行数
select * form 表名 limit 值1,值2

模糊查询:

-- %可以代指一个或多个字符,_一个字符
select * form 表名 where 字段名 like "%def"
select * form 表名 where 字段名 like "abc%"
select * form 表名 where 字段名 like "abcde_"
select * form 表名 where 字段名 like "___def"

查询两个值之间:

1. between
select *from 表名 where num between 18 and 25;
2. &&
select *from 表名 where num >= 18 && num<=25;
3. and
select *from 表名 where num >= 18 and num <= 25;

查询是否为null:

-- 查询表中条件为null
select *from 表名 where 条件 is not null;
--查询表中条件不为null
select *from 表名 where 条件 is null;

聚合函数:

查询有多少条数据:

select count(字段) from 表名;

计算总和:

select sum(字段) from 表名

计算平均值:

select avg(字段) from 表名

计算最大值:.

select max(字段) from 表名

计算最小值:

select min(字段) from 表名

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值