zoukankan      html  css  js  c++  java
  • day42

    #自连接
    select s1.student_id,s1.course_id,s1.number from score as s1,score as s2
    where s1.course_id != s2,course_id and s1.num = s2.num;

    #重定向导入sql命令到文件夹
    tee D:/a.txt
        
    #distinct 去重,必须是放在第一列
    select distinct student.sid,student.sname from score left join studnet on student.sid = score.student_id and score.number >60;

    # Navicat for Mysql 编辑

    pyMysql

    import pymysql

    conn = pymysql.connect(host='localhost',user = 'root',password = '456',database = 'db1',charset = 'utf8')
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

    sql = "select * from student"
    cursor.execute(sql)
    res = cursor.fetchone() #返回一个元组
    #res = cursor.fetchall() 取一行
    #res = cursor.fetchamany() 取多行

    #删除和更新的时候,需要事务提交
    #conn.commit()

    print(res)
    cursor.close()
    conn.close()
  • 相关阅读:
    文件拖拽上传
    30天自制操作系统笔记(第三天)
    PAT 1040到底有几个pat
    pat 1039 到底买不买
    pat 1038 统计同成绩学生
    pat 乙级1034
    pat 乙级1022
    pat 乙级1009
    pat 乙级1008
    pat 乙级1002
  • 原文地址:https://www.cnblogs.com/zhuqihui/p/11025570.html
Copyright © 2011-2022 走看看