mysql增删改查效果_MYsql增删改查

select * from temp;

*代表所有列,temp代表表名,不带条件就查询所有数据

2、 查询指定列和条件的数据

select name, age from temp where age = 22;

查询name和age这两列,age 等于22的数据。

3、 对查询的数据进行运算操作

select age + 2, age / 2, age – 2, age * 2 from temp where age – 2 > 22;

4、 concat函数,字符串连接

select concat(name, ‘-eco’) from temp;

concat和null进行连接,会导致连接后的数据成为null

5、 as 对列重命名

select name as ‘名称’ from temp;

as也可以省略不写,效果一样

如果重命名的列名出现特殊字符,如“‘”单引号,那就需要用双引号引在外面

select name as “名’称” from temp;

6、 也可以给table去别名

select t.name Name from temp as t;

7、 查询常量

类似于SQL Server

select 5 + 2;

select concat('a', 'bbb');

8、 distinct 去掉重复数据

select distinct id from temp;

多列将是组合的重复数据

select distinct id, age from temp;

9、 where 条件查询

大于>、大于等于>=、小于

都可以出现在where语句中

select * from t where a > 2 or a >= 3 or a < 5 or a <= 6 or a = 7 or a <> 0;

10、 and 并且

select * from temp where age > 20 and name = ‘jack’;

查询名称等于jack并且年龄大于20的

11、 or 或者

满足一个即可

select * from tmep where name = ‘jack’ or name = ‘jackson’;

12、 between v and v2

大于等于v且小于等于v2

select * form temp where age between 20 and 25;

13、 in 查询

可以多个条件 类似于or

select * from temp where id in (1, 2, 3);

查询id在括号中出现的数据

14、 like 模糊查询

查询name以j开头的

select * from temp where name like ‘j%’;

查询name包含k的

select * from temp where name like ‘%k%’;

escape转义

select * from temp where name like ‘\_%’ escape ‘\’;

指定\为转义字符,上面的就可以查询name中包含“_”的数据

15、 is null、is not null

查询为null的数据

select * from temp where name is null;

查询不为null的数据

select * from temp where name is not null;

16、 not

select * from temp where not (age > 20);

取小于等于20的数据

select * from temp where id not in(1, 2);

17、 order by

排序,有desc、asc升序、降序

select * from temp order by id;

默认desc排序

select * from temp order by id asc;

多列组合

select * from temp order by id, age;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值