Python学习第二十三课——Mysql 表记录的一些基本操作 (查)
查(select * from 表名)
基本语法:
select <字段1,字段2,...> from <表名> where <表达式>;
例如,查询student表中所有的记录,在终端窗口输入命令:
select id,name,age from employee;
也可以查询限定的记录,输入如下命令,可以限定查询结果为第0条到第1条记录,也就是返回第一条记录:
select * from empolyee limit 0,3;
也可以查询通过年龄限制查询
select * from employee where age between 18 and 20;
模糊查询(like):
select * from employee where name like "阿%";
查询空值:
select name from employee where salary is null;
排序查询(order by)
select name,chengji from employee order by chengji;
select name,chengji from employee where chengji>50 order by chengji;
降序查询:
select name,chengji from employee where chengji>50 order by chengji desc;
as 可以添加一个字段:
select name,chengji1+chengji2 as 总成绩 from employee;
select name,chengji1+chengji2 as 总成绩 from employee order by 总成绩;
分组查询 group by :
注意:按分组条件分组每一组只会显示第一条记录;
select * from employee group by name;(按照name分组 name一样的将被分为一组)
Python学习第二十三课——Mysql 表记录的一些基本操作 (查)的更多相关文章
- Python学习第二十二课——Mysql 表记录的一些基本操作 (增删改)
记录基本操作: 增:(insert into) 基本语法: insert into 表名(字段) values(对应字段的值): 例子1: insert into employee(id,name,a ...
- Python学习第二十一课——Mysql 对数据库的基本操作
数据库操作(DDL) 在数据库下创建表(create_table) 创建表代码块: CREATE TABLE employee( id TINYINT PRIMARY KEY auto_increme ...
- Python学习第二十七课——写一个和Django框架的自己的框架
MyWeb框架: from wsgiref.simple_server import make_server def application(environ, start_response): pri ...
- Python学习第二十课——自定property and classmethod
自定制property class Lazyproperty: def __init__(self,func): # print('==========>',func) self.func=fu ...
- Python学习第十三课——re(正则表达式)模块
.的用法 import re s = 'fhsdjakaxdsancjh' # .代表一个元素,完成模糊匹配 res = re.findall("a..x", s) # 找到s中以 ...
- Python学习-第二天-字符串和常用数据结构
Python学习-第二天-字符串和常用数据结构 字符串的基本操作 def main(): str1 = 'hello, world!' # 通过len函数计算字符串的长度 print(len(str1 ...
- Python学习day43-数据库(多表关系)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- python学习第二次笔记
python学习第二次记录 1.格式化输出 name = input('请输入姓名') age = input('请输入年龄') height = input('请输入身高') msg = " ...
- Python学习day44-数据库(单表及多表查询)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
随机推荐
- Word2010如何从指定页设置页码
光标定位:将光标定位于需要开始编页码的页首位置. 插入分隔符的”下一页”:选择“页面布局—>分隔符—> 下一页”插入. 插入页码:选择“插入—>页码—> 页面底端”,选 ...
- 使用datatable动态添加的顺序与存储的顺序不一致
原因是datatable在展示数据的时候帮助我们排序了 将其禁止排序即可:"ordering":false
- jmeter+influxdb+granfana+collectd监控cpu+mem+TPS
1.安装grafana #####gafana过期安装包安装报错 Error unpacking rpm package grafana-5.1.4-1.x86_64error: unpacking ...
- Linux - Linux中线程为何有PID?
重现 用htop的Tree view(按F5)之后查看线程 参考 https://segmentfault.com/q/1010000003586656 mousycoder的回答 https://u ...
- 密码学笔记——eval(function(p,a,c,k,e,d) 加密破解
密码学笔记——eval(function(p,a,c,k,e,d) 的加密破解 例题: 小明某天在看js的时候,突然看到了这么一段代码,发现怎么也理不出代码逻辑,你能帮帮他吗? 格式:SimCTF{} ...
- VUE style 绑定
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【 SSH 实例】使用ssh开发的简单项目
简单的员工管理项目,使用spring.struts1.hibernate开发 applicationContext.xml <?xml version="1.0" encod ...
- 【资源分享】Half-Life(半条命)中英版
*----------------------------------------------[下载区]----------------------------------------------* ...
- 【12】(难&精)【DFS】矩阵中的路径
题目 矩阵中的路径 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一格开始,每一步可以在矩阵中向左.右.上.下移动一格.如果一条路径经过了矩阵的某一 ...
- 【C语言】scanf()输入浮点型数据
#include<stdio.h> int main() { double x1, x2, x3, x4; printf("输入2个浮点数x1,x2:\n"); sca ...