#自连接
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()