【脚本语言系列】关于Python数据库处理SQLite数据库,你需要知道的事
来源:互联网 发布:ubuntu mysql 重启 编辑:程序博客网 时间:2024/05/16 07:25
如何使用SQLite数据库
# -*- coding:utf-8 -*-import sqlite3conn = sqlite3.connect("enterprise.db")curs = conn.cursor()curs.execute('''CREATE TABLE zoo(critter VARCHAR(20) PRIMARY KEY,count INT,damages FLOAT)''')curs.execute("INSERT INTO zoo VALUES('duck',5, 0.0)")curs.execute("INSERT INTO zoo VALUES('bear',2, 1000.0)")ins = "INSERT INTO zoo (critter, count, damages) VALUES(?,?,?)"curs.execute(ins, ("weasel", 1, 2000.0))curs.execute("SELECT * FROM zoo")rows = curs.fetchall()print(rows)curs.execute("SELECT * from zoo ORDER BY count")rows = curs.fetchall()print(rows)curs.execute("SELECT * from zoo ORDER BY count DESC")rows = curs.fetchall()print(rows)curs.execute('''SELECT * FROM zoo WHERE damages = (SELECT MAX(damages) FROM zoo)''')rows = curs.fetchall()print(rows)curs.close()conn.close()
[(u'duck', 5, 0.0), (u'bear', 2, 1000.0), (u'weasel', 1, 2000.0)][(u'weasel', 1, 2000.0), (u'bear', 2, 1000.0), (u'duck', 5, 0.0)][(u'duck', 5, 0.0), (u'bear', 2, 1000.0), (u'weasel', 1, 2000.0)][(u'weasel', 1, 2000.0)]
Introducing Python;[美]Bill Lubanovic;2016
Python 语言及其应用;【美】Bill Lubanovic;2016
阅读全文
0 0
- 【脚本语言系列】关于Python数据库处理SQLite数据库,你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLite,你需要知道的事
- 【脚本语言系列】关于Python数据库处理MySQL, 你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLAlchemy,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理dbm,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理memcached,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理redis,你需要知道的事
- 【脚本语言系列】关于Python数据库编程ODBC,你需要知道的事
- 【脚本语言系列】关于Python数据库访问DAO, 你需要知道的事
- 【脚本语言系列】关于Python数据库访问ActiveXDataObject,你需要知道的事
- 【脚本语言系列】关于Python数据库访问专用模块,你需要知道的事
- 【脚本语言系列】关于Python系统管理,你需要知道的事
- 【脚本语言系列】关于Python容器,你需要知道的事
- 【脚本语言系列】关于Python音频处理DirectSound, 你需要知道的事
- 【脚本语言系列】关于Python图像处理PIL,你需要知道的事
- 【脚本语言系列】关于Python基础知识处理字符串,你需要知道的事
- 【脚本语言系列】关于Python异常处理,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理YAML,你需要知道的事
- 学习互联网架构第六课(使用wait/notify模拟Queue)
- BBS麦克风、JBL音响联手打造潮州维也纳音乐会所高端声乐系统
- 【Java并发】- StampedLock实现浅析
- eclipse构建maven project 的web项目,勾选Create a simple project < =1= >
- Spring 4.1新特性-综述
- 【脚本语言系列】关于Python数据库处理SQLite数据库,你需要知道的事
- html中如何实现a标签的点击事件
- Hadoop作业提交分析(四)
- 在git上创建并存储 project的相关命令
- pyCharm 2017 激活码
- linux服务器上配置tomcat以service方式启动
- SylixOS 虚拟设备文件浅析
- 浏览器缓存机制
- 远程连接数据库报#1728错误的解决办法