mysqlupdateselect从查询结果中更新数据
在遇到需要update设置的参数来⾃从其他表select出的结果时,需要把update和select结合使⽤,不同数据库⽀持的形式不⼀样,在mysql中如下: update A inner join(select id,name from B) c on A.id = c.id set A.name = c.name;
根据AB两个表的id相同为条件,把A表的name修改为B的sql语句就如上所。
复杂的:
UPDATE user_online_month_atu a
mysql中selectINNER JOIN (
SELECT
user_id,
line_times) as online_times,
SUM(c.login_count) as login_count,
Sum(c.view_page_count) as view_page_count,
LEFT(c.log_date,length(c.log_date) - 2) as date
FROM
user_online_time_atu c
GROUP BY
c.user_id ,date
) b ON a.user_id = b.user_id AND a.`month`=b.date
line_time = b.online_times ,a.login_count=b.login_count,a.view_page_count=b.view_page_count
UPDATE user_online_month a
INNER JOIN (
SELECT
user_id,
line_times) as online_times,
SUM(c.login_count) as login_count,
Sum(c.view_page_count) as view_page_count,
LEFT(c.log_date,length(c.log_date) - 2) as date
FROM
user_online_time c
GROUP BY
c.user_id ,date
) b ON a.user_id = b.user_id AND a.`month`=b.date
line_time = b.online_times ,a.login_count=b.login_count,a.view_page_count=b.view_page_count;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。