怎樣用update語句多表關聯?

怎樣用update語句多表關聯?

怎樣用update語句多表關聯?

update語句多表關聯的方法:

1) 最簡單的形式

SQL 代碼

?–經確認customers表中所有customer_id小于1000均為’北京’

--1000以內的均是公司走向全國之前的本城市的老客戶:) update?customers set?city_name='北京' where?customer_id<p>?</p><p>2) 兩表(多表)關聯update -- 僅在where字句中的連接</p><p>SQL 代碼</p><pre class="brush:php;toolbar:false">--這次提取的數據都是VIP,且包括新增的,所以順便更新客戶類別 update?customers?a?--?使用別名 set?customer_type='01'?--01?為vip,00為普通 where?exists?(select?1 from?tmp_cust_city?b where?b.customer_id=a.customer_id )

3) 兩表(多表)關聯update — 被修改值由另一個表運算而來

SQL 代碼

update?customers?a?--?使用別名 set?city_name=(select?b.city_name?from?tmp_cust_city?b?where?b.customer_id=a.customer_id) where?exists?(select?1 from?tmp_cust_city?b where?b.customer_id=a.customer_id ) --?update?超過2個值 update?customers?a?--?使用別名 set?(city_name,customer_type)=(select?b.city_name,b.customer_type from?tmp_cust_city?b where?b.customer_id=a.customer_id) where?exists?(select?1 from?tmp_cust_city?b where?b.customer_id=a.customer_id )一、隨機密碼生成。編寫程序在26個字母大小寫和9個數字組成的列表中隨機生成10個8位密碼。 ????import?random ????def?random_password(): ????????list1?=?[] ????????#把字母加入序列中 ????????for?i?in?range(65,90): ????????????list1.append(chr(i)) ????????for?i?in?range(97,122): ????????????list1.append(chr(i)) ???????????? ????????list2?=?[1,2,3,4,5,6,7,8,9] ????????list?=?list1?+list2 ????????n?=?0 ????????while?n?<p>推薦教程:《<a href="https://www.php.cn/course/list/50.html" target="_blank">sql視頻教程</a>》</p>

? 版權聲明
THE END
喜歡就支持一下吧
點贊13 分享