pymysql与%s(参数占位符)执行联合查询时

lbsnaicq  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(360)


以下是关于联合查询的代码:

smith ='Smith'
        smithb='Smith'

        sql="""SELECT Distinct Pnumber FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE Dnum = Dnumber AND Mgr_ssn=Ssn AND Lname= %s 
        UNION SELECT Distinct Pnumber PROJECT, WORKS_ON, EMPLOYERE WHERE Pnumber =Pno AND Essn=Ssn AND Lname=%s"""

        curs.execute(sql,(smith,smithb))
        #curs.execute(sql2,('Smith'))
        conn.commit()     
        rows = curs.fetchall()
        print(rows)

这是错误消息!!:

pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE Pnumber =Pno AND Essn=Ssn AND Lname='Smith'' at line 1")

我需要知道pymysql联合查询语法。谢谢。

uujelgoq

uujelgoq1#

试着改变 Lname= %sLname LIKE '%s' .

相关问题