首页 > 解决方案 > MySql,在 ON DUPLICATE KEY 内的子查询中使用值

问题描述

我有疑问:

Insert into target_counts 
            (target_id, email)  
     values (111, 'aa@aa.aa')
ON DUPLICATE KEY UPDATE 
                updated = NOW(), 
                ref_count= (SELECT Count(DISTINCT t.id) 
                            FROM targets t
                                INNER join some_other_table sot on sot.target_id = t.id  
                                sot.email = VALUES(email)
                            )

但有错误

'Unknown column 'email' in 'on clause''

是否有机会在 ON DUPLICATE KEY 子查询中使用 VALUES?

标签: mysqlsql

解决方案


推荐阅读