gpt4 book ai didi

mysql - 根据其自己的表中的值更新列

转载 作者:行者123 更新时间:2023-11-29 09:13:39 24 4
gpt4 key购买 nike

基本上我正在尝试执行此查询

UPDATE communication_relevance SET score = (SELECT ((ces.EXPERT_SCORE * cirm.CONSUMER_RATING) + (12.5 * scs.SIMILARITY)* (1 - EXP(-0.5 * (cal.TIPS_AMOUNT / AT.AVG_TIPS)) + .15))AS ANSWER_SCORE
FROM COMMUNICATION_RELEVANCE AS cr
JOIN network_communications AS nc
ON cr.COMMUNICATION_ID=nc.COMMUNICATIONS_ID
JOIN consumer_action_log AS cal
ON cr.ACTION_LOG_ID=cal.ACTION_LOG_ID
JOIN communication_interest_mapping AS cim
ON nc.PARENT_COMMUNICATIONS_ID=cim.COMMUNICATION_ID
JOIN consumer_interest_rating_mapping AS cirm
ON cr.CONSUMER_ID=cirm.CONSUMER_ID
AND cim.CONSUMER_INTEREST_EXPERT_ID=cirm.CONSUMER_INTEREST_ID
JOIN consumer_expert_score AS ces
ON nc.SENDER_CONSUMER_ID=ces.CONSUMER_ID
AND cim.CONSUMER_INTEREST_EXPERT_ID=CONSUMER_EXPERT_ID
JOIN survey_customer_similarity AS scs
ON cr.CONSUMER_ID=scs.CONSUMER_ID_2
AND cal.SENDER_CONSUMER_ID=scs.CONSUMER_ID_1
OR cr.CONSUMER_ID=scs.CONSUMER_ID_1
AND cal.SENDER_CONSUMER_ID=scs.CONSUMER_ID_2
CROSS JOIN
(SELECT AVG(TIPS_AMOUNT) AS AVG_TIPS
FROM CONSUMER_ACTION_LOG
JOIN COMMUNICATION_RELEVANCE
ON CONSUMER_ACTION_LOG.SENDER_CONSUMER_ID=COMMUNICATION_RElEVANCE.consumer_id) AT)
;

但我收到此错误:

Error:1/25/2011 1:03:20 PM 0:00:00.135: Lookup Error - MySQL Database Error: You can't specify target table 'communication_relevance' for update in FROM clause

任何帮助将不胜感激!

最佳答案

您可以使用 UPDATE (.. JOIN ..) SET 语法

UPDATE communication_relevance X
JOIN (
SELECT cr.COMMUNICATION_ID, ((ces.EXPERT_SCORE * cirm.CONSUMER_RATING)
+ (12.5 * scs.SIMILARITY)
* (1 - EXP(-0.5 * (cal.TIPS_AMOUNT / AT.AVG_TIPS)) + .15)) AS ANSWER_SCORE
FROM COMMUNICATION_RELEVANCE AS cr
JOIN network_communications AS nc ON cr.COMMUNICATION_ID=nc.COMMUNICATIONS_ID
JOIN consumer_action_log AS cal ON cr.ACTION_LOG_ID=cal.ACTION_LOG_ID
JOIN communication_interest_mapping AS cim ON nc.PARENT_COMMUNICATIONS_ID=cim.COMMUNICATION_ID
JOIN consumer_interest_rating_mapping AS cirm ON cr.CONSUMER_ID=cirm.CONSUMER_ID
AND cim.CONSUMER_INTEREST_EXPERT_ID=cirm.CONSUMER_INTEREST_ID
JOIN consumer_expert_score AS ces ON nc.SENDER_CONSUMER_ID=ces.CONSUMER_ID
AND cim.CONSUMER_INTEREST_EXPERT_ID=CONSUMER_EXPERT_ID
JOIN survey_customer_similarity AS scs ON
cr.CONSUMER_ID=scs.CONSUMER_ID_2 AND cal.SENDER_CONSUMER_ID=scs.CONSUMER_ID_1
OR cr.CONSUMER_ID=scs.CONSUMER_ID_1 AND cal.SENDER_CONSUMER_ID=scs.CONSUMER_ID_2
CROSS JOIN
(
SELECT AVG(L.TIPS_AMOUNT) AS AVG_TIPS
FROM CONSUMER_ACTION_LOG L
JOIN COMMUNICATION_RELEVANCE R ON L.SENDER_CONSUMER_ID=R.consumer_id
) AT
) ON X.COMMUNICATION_ID = AT.COMMUNICATION_ID
SET X.score = AT.ANSWER_SCORE;

作为其他阅读本文的人的概念证明,您可以创建一个表格并尝试其语法

create table user_news(
user_id int, article_id int, article_date timestamp,
primary key(user_id, article_id));
insert into user_news select 1,2,'2010-01-02';
insert into user_news select 1,3,'2010-01-03';
insert into user_news select 1,4,'2010-01-01';
insert into user_news select 2,1,'2010-01-01';
insert into user_news select 2,2,'2010-01-02';
insert into user_news select 2,3,'2010-01-02';
insert into user_news select 2,4,'2010-01-02';
insert into user_news select 4,5,'2010-01-05';

现在运行更新(它将所有记录的article_date 设置为同一用户的最大article_date)

update user_news a
join (
select b.user_id, max(b.article_date) adate
from user_news b
group by b.user_id) c
on a.user_id=c.user_id
set a.article_date = c.adate;

最后,检查内容

select * from user_news;

关于mysql - 根据其自己的表中的值更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4797188/

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