为什么SQL插入不正确的值?

问题描述

我正在用Python编写一个SQL查询,该查询将新值插入SQL表的末尾。

month = str(pd.to_datetime(datetime.datetime.strptime(current_month,"%B").replace(year = current_year)))[:7]

more_orders = int(total.iloc[-1][0] - total.iloc[-1][4] * total.iloc[-1][0])
more_sales = total.iloc[-1][1] - total.iloc[-1][5] * total.iloc[-1][1]

st.write(more_sales)
st.write(more_orders)

insertQuery = "insert into TABLE values ({},'First-time',{},0.0)".format(month,more_orders,more_sales)
insertStmt = ibm_db.exec_immediate(connection,insertQuery)

customer_type = 'Returning'
more_orders = int(total.iloc[-1][0])
more_sales = total.iloc[-1][1]

insertQuery2 = "INSERT INTO TABLE VALUES ({},'Returning',more_sales)
insertStmt2 = ibm_db.exec_immediate(connection,insertQuery2)

current_monthcurrent_year是用户定义的值。

我不理解的代码有两个问题。

当month ='2020-08'时,SQL会将其记录为'2012'。

为什么会这样?我什至在变量中打印了值,以确保它具有'2020'-08'。是的。

此外,SQL将这些值插入表的开头。我想将值插入表格的末尾。

我正在使用IBM DB2数据库。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)