我正在尝试编写具有SELECT条件和WHEREORDER BY查询。

我在MySQL中有查询,并希望将其转换为Python

这是我的Mysql-查询:

SELECT StoreId
     , ProductCode
     , TotalQuantity
FROM storeinvoicedetails
WHERE StoreId=1
ORDER BY ProductCode


这是我在Python中尝试过的:

sql = "SELECT StoreId,ProductCode,TotalQuantity FROM storeinvoicedetails  \
       WHERE StoreId = '%d'" % (1) \
       "ORDER BY '%s' '%s'" % ('ProductCode','ASC')

最佳答案

   query =  """SELECT StoreId,ProductCode,TotalQuantity FROM storeinvoicedetails WHERE StoreId={0} ORDER BY ProductCode ASC""".format(store_id)

10-07 14:01