PHP之Mysql常用SQL语句示例的深入分析
发布时间:2024-05-05 09:31:21
1.插入数据
insert into表名(列名1,列名2,列名..) values(值1,值2,值...);
insert into product(name, price, pic_path) values('Nike',500,'uploads/3245.jpg');
2.更新数据
update 表名set列名1=值1,列名2=值2[where条件];
update product set name='LiNing', price=50where id=2;
3.删除数据
deletefrom表名[where条件];
deletefrom product where id=2;
4.查询所有数据
select*from表名;select*from product;
5.查询部份列
select列名1,列名2,列名N from表名;
select name, price from product;
6.条件查询
# 比较 =, <, >, <=, >=, !=
select*from表名where列名=值;
select*from product where id=2;
# and 与
select*from表名where条件1and条件2and条件N;
select*from product where name='Nike'and price=50;
# or 或
select*from表名where条件1or条件2or条件N;
select*from product where name='Nike'or price>50;
# not 非
select*from表名wherenot条件1;
select*from product wherenot name='Nike';
#in 枚举
select*from表名where列名in(值1,值2,值N);
select*from product where id in(2,3,4,10);
select*from product where id notin(2,3,4,10);
#like 模糊查询
select*from表名where列名 like '%值%';
select*from product where name like '%Li%';
#between...and... 范围查询
select*from表名where列名 between 值and值;
select*from order where created between '2010-01-01'and'2011-01-01';
7.查询排序
select*from表名 order by列名排序方式;
#排序方式: asc(升序,默认),desc(降序)
select*from product order by created desc;
8.限制查询结果数量
select*from表名 limit 开始记录数,结果数量;select*from product limit 5;
select*from product limit 2,5;
9.聚合函数
# count 总记录数
select count(列名)from student;
select count(id)from student;
# sum 总共
select sum(列名)from student;
select sum(age)from student;
# avg 平均值
select avg(列名)from student;
select avg(age)as avg_age from student;
# max 最大值
select max(列名)from student;
select max(age)from student;
# min 最小值
select min(列名)from student;
select min(age)from student;
10.子查询
select name from student where age<(select avg(age)from student );
select*from product where id in(select id from order );
11.连接查询
select s.username as stu_name, t.name as te_name from student s, teacher t where s.teacher_id=t.id;


猜你喜欢
- Django结合ajax进行页面实时更新踩过的坑简单记录一下在使用Django、echarts和ajax实现数据动态更新时遇到的一些坑: 1
- 我就废话不多说了,大家还是直接看代码吧!'''Created on 2018-4-4'''k
- 之前有聊过 golang 的协程,我发觉似乎还很理论,特别是在并发安全上,所以特结合网上的一些例子,来试验下go routine中 的 ch
- 一:什么是数据库,为什么要有数据库?数据,数据库,数据库管理系统和数据库系统是与数据库技术密切相关的四个基本概念。数据库相信大家都耳熟能详了
- 目录通过python的tkinter实现简单的注册登录代码截图登录页面注册页面个人主页修改个人信息失败修改个人信息成功重新登录twb总结通过
- 目录1)Golang字符串包含功能[区分大小写]2)Golang ContainsAny()[区分大小写]3)Golang Count()
- 一、反射概述反射是指程序在运行期间对程序本身进行访问和修改的能力。程序在编译过程中变量会被转换为内存地址,变量名不会被编译器写入到可执行部分
- 最近在刚从tensorflow转入pytorch,对于自定义的nn.Module 碰到了个问题,即使把模组 modle=Model().cu
- 本文实例为大家分享了python实现银行实战系统的具体代码,供大家参考,具体内容如下先附上源代码:│ admin.py  
- 双屏不是什么新鲜事,不过相信国内前端工程师还是用单屏的多,前端开发需要同时开启的屏幕太多了…你有没有迷失windows任务栏下n个窗口和AL
- django启动我们在启动一个django项目的时候,无论你是在命令行执行还是在pycharm直接点击运行,其实都是执行'runse
- 记住:这时候08安装的时候要自定义一个实例 比如:mysql2008(不能在使用默认实例了) sql server 2008 express
- 今天写了个小功能,看起来挺简单,写的过程中发现了些坑。1.div没有disabled的属性,所以得写成button2.disabled在da
- pip是什么其实,pip就是 Python标准库(The Python Standard Library)中的一个包,这个包比较特殊,用它可
- 先看看效果:效果-点击弹出弹框 -点击复选框,已选div中 显示已选中的选项 -再次点击取消选中状态,已选div中 显示的选中选项取消显示
- 这个仿msn的右下角popup提示窗口效果很久以前收集的,现在整理出来给大家分享,需要的朋友可以拿去用,特点,提示窗口内容和js代码分离容易
- MERGE存储引擎把一组MyISAM数据表当做一个逻辑单元来对待,让我们可以同时对他们进行查询。构成一个MERGE数据表结构的各成员MyIS
- 如下所示:data = np.random.randn(20)factor = pd.cut(data,4)pd.get_dummies(f
- 写爬虫似乎没有比用 Python 更合适了,Python 社区提供的爬虫工具多得让你眼花缭乱,各种拿来就可以直接用的 library 分分钟
- 什么是Batch NormalizationBatch Normalization是神经网络中常用的层,解决了很多深度学习中遇到的问题,我们