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- ...
随机推荐
- MySQL8.0服务启动(windows10)
mysql下载地址:https://dev.mysql.com/downloads/mysql/ 根目录下配置文件:my.ini [mysqld]# 设置3306端口port=3306# 设置mysq ...
- 如何将mongo查询结果导出到文件中
1.新建一个js文件,将查询方法写进去,如dump.js,文件内容如下 var c = db.campaign.find({status:1}).limit(5) while(c.hasNext()) ...
- Java入门学习路线目录索引
原创 Java入门学习路线目录索引 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/One_ ...
- js实现图片选中马上显示功能,选择后可以预览,即选即显
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 数据库程序接口——JDBC——API解读第二篇——执行SQL的核心对象
结构图 核心对象 Statement Statement主要用来执行SQL语句.它执行SQL语句的步骤为: 第一步:创建statement对象. 第二步:配置statement对象,此步骤可以忽略. ...
- Python 之路
Python之路[第一篇]:Python简介和入门 Python之路[第二篇]:Python基础(一) Python之路[第三篇]:Python基础(二) Python之路[第四篇]:模块 Pytho ...
- 深入delphi编程理解之消息(四)使用TWMSysCommand结构体的WM_SysCommand消息应用
通过以下实例拦截窗体WM_SysCommand消息,我们可以获取到很多有趣的数据. 一.程序界面 二.程序代码 unit Unit1; interface uses Windows, Messages ...
- C#面向对象三大特性:多态
什么是多态 公司最近为了陶冶情操,养了几种动物(Animal),有猫(Cat).狗(Dog).羊(Sheep),这些动物都有共同的特性,会吃(Eat).会叫(Shout),但是它们吃的不同,叫的也不同 ...
- 【Math】高数-一个有趣的旋转体体积与面积
Go confidently in the direction of your dreams. Live the life you've imagined. 题目 设曲线 \(y = \tfrac{1 ...
- SmartRobotControlPlateform——智能机器人控制平台
具体成果参考github项目:https://github.com/ecjtuseclab/SmartRobotControlPlateform 这里我使用的镜像是:2018-11-13-raspbi ...