简体   繁体   English

表'tbl_name'被指定两次,既作为'UPDATE'的目标,又作为数据的单独源

[英]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.

相关问题 表名称指定两次作为更新目标和单独的数据源 - Table name specified twice both as a target for update and separate source for data 表名指定两次,既作为更新的目标,又作为单独的数据源 - Table name specified twice, both as a target for update and as a separate source for data 表被指定两次,既作为 &#39;UPDATE&#39; 的目标,也作为单独的数据源 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data 表被指定两次,既作为&#39;UPDATE&#39;的目标,又作为单独的数据源 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data MySQL-表两次指定为更新目标和单独数据源 - MySQL - table specified twice both as a target for update and as a separate source for data 表被指定两次,既作为 &#39;UPDATE&#39; 的目标,也作为 mysql 中数据的单独源 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data in mysql 错误: <table_name> 指定两次,既作为“ UPDATE”的目标,又作为单独的数据源 - Error : <table_name> specified twice, both as a target for 'UPDATE' and as a separate source for data 该表被两次指定为INSERT的目标和单独的数据源 - table is specified twice both as a target for INSERT and as separate source of data 错误代码:1093。表&#39;site_html&#39;被指定两次,既作为&#39;UPDATE&#39;的目标又作为数据的单独来源 - Error Code: 1093. Table 'site_html' is specified twice, both as a target for 'UPDATE' and as a separate source for data #1093-表&#39;filtros&#39;被指定两次,既作为&#39;UPDATE&#39;的目标,又作为数据的单独源 - #1093 - Table 'filtros' is specified twice, both as a target for 'UPDATE' and as a separate source for data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM