当前位置:首页 » 《随便一记》 » 正文

MySQL数据库中常用SQL语句

8 人参与  2022年11月07日 13:37  分类 : 《随便一记》  评论

点击全文阅读


开发过程中我们经常会用到各种SQL语句,今天小编就来和大家分享一些简单的SQL语句的使用,便于大家对于项目的开发。

1、查询:查询本字段带文字的数据。
select * from student  where (not  age  regexp '^[1-9A-Za-z]')  and age  != '';

2、修改:把学生表中年龄为38的数据改为空字符串。

UPDATE student  set age= '空白,什么也不写'  WHERE  age='38';

3、模糊查询:模糊查询邮箱列中带有@的数据并去重,DISTINCT代表去重。

SELECT DISTINCT  studentId,email from student  WHERE email LIKE '%@% '; 

4、查询:查询id为523452的数据。

select studentId,age  from student where studentId = '523452'; 

5、查询:查询student表全部数据。

SELECT * from student

6、新增:新增一条数据,包含:studentId,name,age,sex,phone,class。

INSERT into student values ('"+studentId+"','"+name+“”','"+age+“”','"+sex+“”','"+phone+“”','"+class+“”');

7、删除:根据id删除数据。

delete from student  where studentId='"+studentId+"';

8、查询:查询邮箱列中是“@”的数据并进行去重。

SELECT DISTINCT  studentId,email from student  WHERE email= '@';

9、查询:查询age列中纯数字的数据。

select * from student  where (age regexp '[^0-9]')=0  and age != ''; 

10、模糊查询:模糊查询email列中带@的数据
SELECT * FROM student   WHERE email  LIKE '%@%'; 

11、模糊查询:牧户查询email中没有@的数据。
SELECT * FROM student   WHERE not email  LIKE '%@%' and not email  = ''; 


点击全文阅读


本文链接:http://zhangshiyu.com/post/47247.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1