zoukankan      html  css  js  c++  java
  • 基于SQL和PYTHON的数据库数据查询select语句

    #xiaodeng
    #python3
    #基于SQL和PYTHON的数据库数据查询语句
    import pymysql

    #1、基本用法
    cur.execute("select * from biao")


    #2、查询某表中的特定数据,如某制定id和名字的数据
    cur.execute("select * from biao where id="XXXX" and name="xxx" ")


    #3、统计函数
    select count(1) from biao


    #4、like模糊查询,比如说统计某姓张的数据,姓张的有多少个数据统计
    select count(*) from biao where name like "张%"


    #5、统计姓张2个字的人数
    select count(*) from biao where name like "张_"

    #6、统计杭州籍的同学数量
    select count(*) from biao where home like "%杭州%"


    #7、查询班上每位学生的年龄
    select name, year(now())-year(birthday) as age from biao


    #8、mysql查询当天的所有信息:
    select * from 表名
    where year(regdate) = year(now()) and month(regdate) = month(now()) and day(regdate) = day(now())
  • 相关阅读:
    1.17 Python基础知识
    反射
    面向对象——类
    异常处理
    面向对象——静态方法、类方法、属性法法,其他特殊方法
    面向对象——继承
    question
    configparser模块
    hashlib模块
    shelve模块
  • 原文地址:https://www.cnblogs.com/dengyg200891/p/5348288.html
Copyright © 2011-2022 走看看