根据MySQL中其他表中的匹配值更新列 [英] Update column based on matching values in other table in mysql

查看:140
本文介绍了根据MySQL中其他表中的匹配值更新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表日历和客户表.日历表有一个客户"列,其中有客户表"ID"作为值.但是不幸的是,此日历客户字段值错误地填充了其他值.这两个表都有这些公共字段Date,SeatingID和BusID.如何基于这些公共字段更新日历表客户字段?

I have two tables calendar and customer table. Calendar table have a "customer" column which has customer table "ID" as value. But unfortunately, this calendar customer field value was wrongly populated with other values. Both tables have these common fields Date, SeatingID and BusID. How to update the calendar table customer field based on these common fields?.

下面是两个表的结构.

客户表

日历表

推荐答案

update calendar ca left join customer c 
on c.DateofTravel=ca.Date and c.SeatingID=ca.SeatingID and c.BusID=ca.BusID 
set 
ca.Customer=c.ID;

这篇关于根据MySQL中其他表中的匹配值更新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆