zoukankan      html  css  js  c++  java
  • pymysql实现从a表过滤出有效信息添加至b表

    # Author: yeshengbao
    # --      coding: utf-8     --
    # @Time  : 2018/4/16  19:23
    
    
    import pymysql
    
    # 创建连接
    conn = pymysql.connect(host='localhost', port=3306, user='root', password="123456", db="test", charset='utf8')
    
    # 获取游标
    cursor = conn.cursor()
    
    # 修改
    # sql_insert = """update user set name='zyx' where id=2"""   #(name='zyx'为修改的内容) where为过滤
    # cursor.execute(sql_insert)
    
    # 查找
    sql_select = """select * from user where name like 'y%'"""  
    aaa = cursor.fetchall()    # fetchall:将返回所有结果,返回二维元组,如(('id','title'),('id','title')),
    cursor.execute(sql_select)
    for i in aaa: 
      ids
    = i[0] names = i[1]
    sql_insert = """insert into users(id, name)values({0},"{1}")""".format(ids, names) # 记住在sql语句里尽量使用双引号, 不然可能会引起报错,详情, 看mysql手册
    conn.commit()
    conn.close()

     查询某个月的数据(查询17年10月份数据)

      select * from exam where date_format(starttime,'%Y-%m')='2017-10'

    查询指定时间段的数据

      select fullName,addedTime FROM t_user where addedTime >='2017-1-1 00:00:00' and addedTime < '2018-1-1 00:00:00';

  • 相关阅读:
    STL目录
    Hola!
    SWPUCTF 2019总结以及部分WP
    SQL手工注入基础篇
    JDK11,JDK12没有JRE的解决方法
    FJUT2019暑假周赛三部分题解
    FJUT2019暑假周赛一题解
    随笔1
    关于针对本校教务系统漏洞的一次信息检索
    KMP算法讲解
  • 原文地址:https://www.cnblogs.com/yijian001/p/8858014.html
Copyright © 2011-2022 走看看