gpt4 book ai didi

python - 当我在 python 中使用 like 和 mysql 时出现警告 1292

转载 作者:行者123 更新时间:2023-11-30 22:03:29 27 4
gpt4 key购买 nike

我必须检查我的数据库中是否有空值,我需要检查 11 列(按 )以及年份(例如 2017%)。

def test():
sql= "select date from a000760 where (total_assets is null or total_liabilities is null or sales_figures is null or sales_cost is null or business_profits is null or gross_margin is null or current_income is null or depreciation_expense_of_tangible_assets is null or liquid_asset is null or noncurrent_asset is null or liquid_liability is null) and (date like '2010%')"
curs.execute(sql)
#year="2010"
#curs.execute("select date from a000760 where (total_assets is null or total_liabilities is null or sales_figures is null or sales_cost is null or business_profits is null or gross_margin is null or current_income is null or depreciation_expense_of_tangible_assets is null or liquid_asset is null or noncurrent_asset is null or liquid_liability is null) and (date like %s)",year)
result = curs.fetchall()
if len(result)>0: // print shows () even if it's none. so, I use this
print "a000760"
print "2010 null exists"

是一张表的测试版。我必须检查 2000 多个表。它适用于此 def 并显示错误(仅适用于一个表)。但它不适用于总表。我得到这个错误:

Warning: (1292, "Incorrect date value: '2010%' for column 'date' at row 1")

不知道怎么...我搜索了整个语法,但是当我输入 %2017% 时,它不起作用。

最佳答案

不要对日期使用like!日期不是字符串。

你可以这样做:

year(date) = 2010

或者:

date >= '2010-01-01' and date < '2011-01-01'

关于python - 当我在 python 中使用 like 和 mysql 时出现警告 1292,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42569938/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com