[英]Table 'tbl_name' is specified twice, both as a target for 'UPDATE' and as a separate source for data
I am facing issue during the execution of the following query 我在执行以下查询期间遇到问题
UPDATE tbluser_payment
SET payment_date = SUBSTRING(payment_date, 1, 2) + 1
WHERE
trans_updatetime IN (
SELECT
trans_updatetime
FROM
`tbluser_payment`
WHERE
DAY (
cast(trans_updatetime AS date)
) IN ('28', '29', '30', '31')
)
I searched through many questions but get nothing to related with this query they were inserting record into the database . 我搜索了许多问题,但没有发现与此相关的问题,他们将记录插入数据库。
I want to update payment_date
coloumn with 1 if where clause return true 如果where子句返回true,我想用1更新
payment_date
Is this is possible through this way ? 这样可以做到吗?
Any Help Will be Appreciated 任何帮助将不胜感激
Thanks! 谢谢!
I don't think a sub-query is needed here. 我认为这里不需要子查询。 Use the condition in the where clause.
在where子句中使用条件。
UPDATE tbluser_payment
SET payment_date = SUBSTRING(payment_date, 1, 2) + 1
WHERE DAY(cast(trans_updatetime AS date)) IN ('28', '29', '30', '31')
Edit: Use if
to set the payment_date column in mmyyyy format. 编辑:
if
以mmyyyy格式设置payment_date列, if
使用该选项。
UPDATE tbluser_payment
SET payment_date = IF(length(SUBSTRING(payment_date, 1, 2) + 1) < 2,
'0' + SUBSTRING(payment_date, 1, 2) + 1,
SUBSTRING(payment_date, 1, 2) + 1
)
+ SUBSTRING(payment_date, 3)
WHERE DAY(cast(trans_updatetime AS date)) IN ('28', '29', '30', '31')
and SUBSTRING(payment_date, 1, 2) <> 12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.