[英]How to write a query that joins same table in sql and compares the column values of one table with same column in another table
[英]How to write an SQL command to input a column by using data from another column in the same table?
在這里,我想為每位員工生成密碼,密碼是對應的employee_ID的后6位數字。 什么是必需的SQL語句? 謝謝
Employee_ID | Password
------------------------
E200102 | NULL
E199500 | NULL
E200410 | NULL
E199606 | NULL
E200303 | NULL
E199206 | NULL
E198703 | NULL
E198405 | NULL
預期結果如下。
Employee_ID | Password
------------------------
E200102 | 200102
E199500 | 199500
E200410 | 200410
E199606 | 199606
E200303 | 200303
E199206 | 199206
E198703 | 198703
E198405 | 198405
似乎您只想為此刪除firts字符,可以更新並使用substr()
Update your_table
set password = substr(Employee_ID , 2);
https://dev.mysql.com/doc/refman/8.0/zh-CN/string-functions.html#function_substr
嘗試這個
UPDATE Table_Name SET password = SUBSTR(Employee_ID, 2);
這將遍歷your_table_anme中的所有行,並將密碼替換為減去第一個字符的密碼。
試試下面的,
Update Table_Name
Set Password = Substr(Employee_ID, 2)
此查詢基本上從employee_id中刪除第一個字符,並將其更新為密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.