热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

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

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
推荐阅读
author-avatar
马先生2502911467
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有