欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL学习笔记五去重,给新加字段赋值的方法

程序员文章站 2023-12-15 21:46:58
去掉数据重复 增加两个字段 alter table t_employee add fsubcompany varchar(20); alter table t_employ...
去掉数据重复
增加两个字段
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

上一篇:

下一篇: