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()
     
     
  • 相关阅读:
    python与数据库(SQLServer、MySQL、Redis、MongoDB)
    网络表示学习 图神经网络资料整理
    Java学习笔记 算法 Algorithms Fourth Edition
    word2vec 代码解读
    爬虫python的世界
    mac 字幕生成工具
    CS224W Analysis of Networks
    SNAP macos
    python基础代码
    Keras笔记
  • 原文地址:https://www.cnblogs.com/lzcys8868/p/7888759.html
Copyright © 2011-2022 走看看