zoukankan      html  css  js  c++  java
  • python 基础 9.10 删除数据

     
    #/usr/bin/python
    #-*- coding:utf-8 -*-
    #@Time   :2017/11/24 4:40
    #@Auther :liuzhenchuan
    #@File   :删除数据.py
     
    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # @Time    : 2017/9/23 16:42
    # @Author  : lingxiangxiang
    # @File    : demon10.py
    import MySQLdb
     
    sql = '''delete from teacher WHERE tid in (select tid from ((select score.couid, course.tid, score.grade, count(course.tid) as count_teacher from score join course on course.couid = score.couid and score.grade <60 join teacher on teacher.tid = course.tid GROUP BY course.tid ORDER BY count_teacher DESC LIMIT 5) as tid_test));'''
     
    def connect_mysql():
        db_config = {
            "host": "192.168.16.70",
            "port": 3306,
            "user": "root",
            "passwd": "123123",
            "db": "students",
            "charset": "utf8"
        }
        try:
            cnx = MySQLdb.connect(**db_config)
        except Exception as e:
            raise e
        return cnx
     
    if __name__ == "__main__":
        cnx = connect_mysql()
        cus = cnx.cursor()
        try:
            cus.execute(sql)
            cus.close()
            cnx.commit()
        except Exception as e:
            cnx.rollback()
            raise e
        finally:
            cnx.close()
     
     
  • 相关阅读:
    cocos2dx[3.2](2) 3.x巨变
    cocos2dx[3.2](1) 浅析cocos2dx3.2引擎目录
    cocos2dx基础篇(28) 布景层Layer的三个子类
    cocos2dx基础篇(27) 屏幕适配
    centos 安装 mysql5.6
    centos 安装 mysql5.7.9初始密码问题
    php 计算字符串长度
    mysql tinyint
    php数组
    PHP中9大缓存技术总结
  • 原文地址:https://www.cnblogs.com/lzcys8868/p/7888759.html
Copyright © 2011-2022 走看看