SQL学习笔记五去重,给新加字段赋值的方法_mssql数据库教程-查字典教程网
SQL学习笔记五去重,给新加字段赋值的方法
SQL学习笔记五去重,给新加字段赋值的方法
发布时间:2016-12-29 来源:查字典编辑
摘要:去掉数据重复增加两个字段alterTABLET_EmployeeAddFSubCompanyVARchar(20);ALTERTABLET_...

去掉数据重复

增加两个字段

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

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新mssql数据库学习
    热门mssql数据库学习
    编程开发子分类