删除SQL Server查询中的重复数据 [英] Remove duplication of data in Sql Server query

查看:81
本文介绍了删除SQL Server查询中的重复数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列说TypeOfManager,其中将有类似
的条目
TypeOfManager
-----------------
销售
关系
S
R
在这种情况下,我想将"R"视为关系",将"S"视为销售". sql server中查询的语法是什么.

I am having a column say TypeOfManager where there will be entries like

TypeOfManager
-----------------
Sales
Relation
S
R
In this case i want to treat ''R'' as Relation and ''S'' as Sales. What will be the syntax of the query in sql server.

推荐答案

只需使它们相同:
Just make them the same :
update tablename set TypeOfManager = 'Relation' where TypeOfManager='R' 
GO 
update tablename set TypeOfManager = 'Sales' where TypeOfManager='S' 
GO


尝试查询

try with query

select TypeOfManager ,count(TypeOfManager) as count from Tablename group by TypeOfManager 





问候,
Pal





Regards,
Pal


选择SUM(Sal)AS销售"
,SUM(Rel)AS``关系''
来自(
选择
TypeOfManager之类的情况,例如"Sales",然后1
当TypeOfManager像"S"那么1
ELSE 0
结束于Sal
,当TypeOfManager类似于"Relation"时,则为1
当TypeOfManager像"R"时,那么1
ELSE 0
END AS Rel
来自表名
)g
select SUM(Sal) AS ''Sales''
, SUM(Rel) AS ''Relation''
from (
select
CASE WHEN TypeOfManager like ''Sales'' THEN 1
WHEN TypeOfManager like ''S'' THEN 1
ELSE 0
END AS Sal
, CASE WHEN TypeOfManager like ''Relation'' THEN 1
WHEN TypeOfManager like ''R'' THEN 1
ELSE 0
END AS Rel
from Tablename
)g


这篇关于删除SQL Server查询中的重复数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆