1. 程式人生 > >mysql update 欄位select 內容

mysql update 欄位select 內容

UPDATE hm_opportunities
INNER JOIN (
	SELECT
		id,
		SUBSTRING_INDEX(opportunity_city, '-', 1) AS province
	FROM
		hm_opportunities
) b ON hm_opportunities.id = b.id
SET hm_opportunities.province = b.province;
UPDATE hm_opportunities
INNER JOIN (
	SELECT
		id,
		SUBSTRING_INDEX(opportunity_city, '-', -1) AS city
	FROM
		hm_opportunities
) b ON hm_opportunities.id = b.id
SET hm_opportunities.city = b.city;
  • 更新某個欄位,根據查詢的欄位值
  • update tb inner join (select) on contidions set field=value