程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> SQL學習筆記五去重,給新加字段賦值的方法

SQL學習筆記五去重,給新加字段賦值的方法

編輯:更多數據庫知識

去掉數據重復
增加兩個字段
alter TABLE T_Employee Add FSubCompany VARchar(20);
ALTER TABLE T_Employee ADD FDepartment VARCHAR(20);

給新加的字段賦值
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='Development' where FNumber='DEV001';
UPDATE T_Employee SET FSubCompany='ShenZhen',FDepartment='Development' where FNumber='DEV002';
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='HumanResource' where FNumber='HR001';
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='HumanResource' where FNumber='HR002';
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='InfoTech' where FNumber='IT001';
UPDATE T_Employee SET FSubCompany='ShenZhen',FDepartment='InfoTech' where FNumber='IT002';
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='Sales' where FNumber='SALES001';
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='Sales' where FNumber='SALES002';
UPDATE T_Employee SET FSubCompany='ShenZhen',FDepartment='Sales' where FNumber='SALES003';

查詢並去重
select distinct FDepartment from T_Employee

select distinct FDepartment,FSubCompany from T_Employee

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved