Python 从以前的数据结果中选择数据
对不起。我不熟悉用Python表达SQL语句 我正在尝试选择x。。从上一个查询结果 例如,我有一个第一个查询sql1:Python 从以前的数据结果中选择数据,python,mysql,Python,Mysql,对不起。我不熟悉用Python表达SQL语句 我正在尝试选择x。。从上一个查询结果 例如,我有一个第一个查询sql1: sql1 = 'select course_id, record_id from Courses ' \ ' where ( record_id not in ("TEST", "TEST123")) ' cursor.execute(sql1) e = cursor.fetachall() 当我尝试在不分解查询的情况下执行此操作时,由于不同的数据类型,我得到了
sql1 = 'select course_id, record_id from Courses ' \
' where ( record_id not in ("TEST", "TEST123")) '
cursor.execute(sql1)
e = cursor.fetachall()
当我尝试在不分解查询的情况下执行此操作时,由于不同的数据类型,我得到了一个错误
现在,我如何从sql1中进行选择?这次我必须添加一个数据计算
sql2 = ' select course_id, max(record_id) + 1 from ... ? '
使sql1成为sql2的子查询。例如:
"""select course_id, max(record_id) + 1 from
(select course_id, record_id from Courses
where record_id not in ('TEST', 'TEST123'))"""
您可以使用视图来存储查询。 使用Python,您只需要一个查询
sql1 = 'CREATE OR REPLACE VIEW v AS
select course_id, record_id from Courses
where ( record_id not in ("TEST", "TEST123"));
select course_id, max(record_id) + 1 from v;'
cursor.execute(sql1)
e = cursor.fetachall()
有关视图的更多信息:从选择课程id中选择课程id,maxrecord\u id+1。。。这个Python是从哪里来的?它看起来像微软的脚本View@KingJava是mysql
sql1 = 'CREATE OR REPLACE VIEW v AS
select course_id, record_id from Courses
where ( record_id not in ("TEST", "TEST123"));
select course_id, max(record_id) + 1 from v;'
cursor.execute(sql1)
e = cursor.fetachall()