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- ...
随机推荐
- 用git无法连接github的解决方法
如果要從 GitHub 存取 Git 儲存庫,建議還是多採用 SSH 與 HTTPS 通訊協定最為穩定可靠,因此我的替代方案就是設定 Git 的全域設定值 ( –global ),預設將所有 git: ...
- eclipse报错:unable to install breakpoint in .......due to missing line number attributes
报错信息如下: 解决方案方案1.把断点都干掉,再启动.应该是代码更新后,断点位置没有代码了或位置改变了. 方案2.在Eclipse - Preferences - Java - Complier 下 ...
- 对已经存在的没有唯一标识的表添加一个自增的id字段(利用序列sequence)操作过程
1.原始的数据表 2.操作 -- 创建序列 test_data_file_Id_Seq -- create sequence Test_data_file_Id_Seq increment by 1 ...
- pycharm开发flask指定ip、端口无效
原因分析 是因为使用了pycharm的版本的问题.并不是flask框架本身的问题(不管你是如何设置的flask配置,通过加载config也好,还是通过run的时候传入形参也好,均不影响) 可以很明显的 ...
- GitHub网页版基本操作
创建存储库 登录GitHub进入主页,点击头像左边的加号,创建存储库 填写存储库名称.描述,根据需求设置其他选项.点击“Create repository”按钮 创建分支 打开之前创建好的存储库,点击 ...
- VS2015 编译程序时提示 无法查找或打开 PDB 文件
“mode.exe”(Win32): 已加载“C:\Windows\System32\api-ms-win-core-file-l2-1-0.dll”.无法查找或打开 PDB 文件.“mode.exe ...
- Ubuntu16.04 QT5编译出现cannot find -lGL和collect2:error:ld r
在ubuntu下使用Qt 编译时候遇上了cannot find -lGL错误,使用命令 是由于系统缺少链接库,在终端执行下面命令就可以解决问题. sudo apt-get install libqt4 ...
- 6月28日至7月6日第一周小学期学习c++编程收获
6.28日开始,进入小学期,也就是在10天十天时间内集中练习,以提高编程能力.此次小学期的作业共有十道题,其中分为四大类,系统类,数学类,游戏类,链表类. 我开始的时候面对第一,二题,系统类,因为当时 ...
- async+队列queue.Queue()
import queue import time import random import threading import asyncio import logging logging.basicC ...
- 《爬虫学习》(一)(HTTP协议)
Http请求: 1.在浏览器中发送一个http请求的过程: 2.url详解: URL是Uniform Resource Locator的简写,统一资源定位符. 一个URL由以下几部分组成 scheme ...