[英]formatted sql query doesn't work in python
my code is: 我的代码是:
engine = sqlalchemy.create_engine("credentials")
connection = engine.connect()
day = 180601
query = "select * from Data where Name like '%{0}%'".format(str(day))
df = pd.DataFrame(connection.execute(query).fetchall())
but this doesn't work. 但这不起作用。 when i type:
当我键入:
query = "select * from Data where Name like '%180601%'"
then repeat the same process, this works fine although they produce same queries. 然后重复相同的过程,尽管它们产生相同的查询,但效果很好。 i want to change the days in a for loop.
我想更改for循环中的日期。
Any ideas would be appreciated. 任何想法,将不胜感激。 Thanks in advance!
提前致谢!
I discovered there is no problem with the python itself. 我发现python本身没有问题。 The problem is sql cannot get top 100 of the rows without order by clause.
问题是如果没有order by子句,sql无法获得前100行。 I think this is another bug but adding "order by col1" at the end of query solved the problem.
我认为这是另一个错误,但是在查询末尾添加“由col1排序”可以解决此问题。
Thanks for your time. 谢谢你的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.