使用多个表中的数据更新mysql表

使用多个表中的数据更新mysql表,mysql,sql,Mysql,Sql,我有下面的查询,我想这样做,如果有一个重复的键,它会更新值 INSERT INTO totalData (pageId, dateScanned, totalPageLikes, totalTalkingAbout, totalPos, totalNeg, totalFemales, totalMales, totalStrongPositives, totalPositives, totalWeakPositives, totalNeutrals, totalWeakNegatives, to

我有下面的查询,我想这样做,如果有一个重复的键,它会更新值

INSERT INTO totalData (pageId, dateScanned, totalPageLikes, totalTalkingAbout, totalPos, totalNeg, totalFemales, totalMales, totalStrongPositives, totalPositives, totalWeakPositives, totalNeutrals, totalWeakNegatives, totalNegatives, totalStrongNegatives, totalStatuses, totalStatusLikes, totalStatusShares, totalComments, totalUniqueCommenters)

SELECT pages.pageId, pages.dateScanned, pages.likes, pages.talkingAbout,

SUM(commentTags.tag LIKE '%positive%')   AS positive, 
SUM(commentTags.tag LIKE '%negative%')   AS negative,

SUM(comments.gender = 'female')          AS females,
SUM(comments.gender = 'male')            AS males,

SUM(commentTags.tag = 'strong_positive') AS strongPositives,
SUM(commentTags.tag = 'positive')    AS positives,
SUM(commentTags.tag = 'weak_positive')   AS weakPositives,
SUM(commentTags.tag = 'neutral')         AS neutrals,
SUM(commentTags.tag = 'weak_negative')   AS weakNegatives,
SUM(commentTags.tag = 'negative')    AS negatives,
SUM(commentTags.tag = 'strong_negative') AS strongNegatives,

COUNT(DISTINCT statuses.statusId)    AS totalStatuses,
SUM(DISTINCT statuses.likesCount)    AS totalLikesCount,
SUM(DISTINCT statuses.sharesCount)       AS totalSharesCount,
COUNT(DISTINCT comments.commentId)   AS totalComments,
COUNT(DISTINCT comments.userName)        AS uniqueUsers

FROM pages
JOIN statuses ON pages.pageId = statuses.pageId AND pages.dateScanned = statuses.dateScanned
JOIN comments ON comments.statusID = statuses.statusId
JOIN commentTags ON comments.commentId = commentTags.commentId

WHERE pages.pageId = '115798033817' AND pages.dateScanned = '2013-11-05'
我在重复密钥更新上尝试了
,这就是我进一步修改查询的方式

ON DUPLICATE KEY UPDATE 
totalData.pageId = pageId, totalData.dateScanned = dateScanned, 
totalData.totalPageLikes = totalPageLikes, totalData.totalTalkingAbout = totalTalkingAbout,
totalData.totalPos = positive, totalData.totalNeg = negative, totalData.totalFemales = females, 
totalData.totalMales = males, totalData.totalStrongPositives = strongPositives, 
totalData.totalPositives = positives, totalData.totalWeakPositives = weakPositives, 
totalData.totalNeutrals = neutrals, totalData.totalWeakNegatives = weakNegatives, 
totalData.totalNegatives = negatives, totalData.totalStrongNegatives = strongNegatives, 
totalData.totalStatuses = totalStatuses, totalData.totalStatusLikes = totalLikesCount, 
totalData.totalStatusShares = totalSharesCount, totalData.totalComments = totalComments, 
totalData.totalUniqueCommenters = uniqueUsers ;

但是当我运行查询时,它在字段列表中显示
未知列“正”

得到了它,我必须使用
VALUES()
函数,因此重复键更新时的
部分查询如下所示

ON DUPLICATE KEY UPDATE 
                        totalPageLikes = VALUES(totalPageLikes), totalTalkingAbout = VALUES(totalTalkingAbout), 
                        totalPos = VALUES(totalPos), totalNeg = VALUES(totalNeg), totalFemales = VALUES(totalFemales), totalMales = VALUES(totalMales), 
                        totalStrongPositives = VALUES(totalStrongPositives), totalPositives = VALUES(totalPositives), totalWeakPositives = VALUES(totalWeakPositives), 
                        totalNeutrals = VALUES(totalNeutrals), totalWeakNegatives = VALUES(totalWeakNegatives), totalNegatives = VALUES(totalNegatives), totalStrongNegatives = VALUES(totalStrongNegatives), 
                        totalStatuses = VALUES(totalStatuses), totalStatusLikes = VALUES(totalStatusLikes), totalStatusShares = VALUES(totalStatusShares), 
                        totalComments = VALUES(totalComments), totalUniqueCommenters = VALUES(totalUniqueCommenters) ";

你的问题是?在我的帖子末尾。。。“但当我运行查询时,它会在字段列表中显示未知列‘肯定’。”。。。如何修复此问题?错误消息非常清楚。。“肯定”列不存在。能否检查查询是否正确?