共計 1591 個字符,預計需要花費 4 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
丸趣 TV 小編給大家分享一下如何使用 update 語句多表關聯?,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
怎樣用 update 語句多表關聯?
update 語句多表關聯的方法:
1) 最簡單的形式
SQL 代碼
– 經確認 customers 表中所有 customer_id 小于 1000 均為 北京
--1000 以內的均是公司走向全國之前的本城市的老客戶:)
update customers
set city_name= 北京
where customer_id 1000
2) 兩表 (多表) 關聯 update — 僅在 where 字句中的連接
SQL 代碼
-- 這次提取的數據都是 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 10:
password = []
n = n + 1
m = 0
password = password + random.sample(list, 8)
# 把列表轉化為字符串
password_middle = [str(i) for i in password]
password_end = .join(password_middle)
print(第 {} 個隨機生成的密碼是:{} .format(n,password_end))
random_password()
#random.sample(seq, k)實現從序列或集合 seq 中隨機選取 k 個獨立的的元素
#random.randint(a, b) #A-Z:65-90;a-z:97-122;ASCII 碼 48~57 為 0 到 9 十個阿拉伯數字
看完了這篇文章,相信你對如何使用 update 語句多表關聯?有了一定的了解,想了解更多相關知識,歡迎關注丸趣 TV 行業資訊頻道,感謝各位的閱讀!
向 AI 問一下細節
正文完