Home  >  Article  >  Database  >  sql server 统计数据库中某个字段的值,剔除重复数据和查找重复

sql server 统计数据库中某个字段的值,剔除重复数据和查找重复

WBOY
WBOYOriginal
2016-06-07 15:30:141731browse

1.有的时候,在数据库中存在一些重复的数据,但是我们又想统计某个字段的,重复的要剔除掉,如图所示: 在上面的图我们可以看到,id=2,3 id=4,5的4条数据都重复了,我们统计amount只要其中的一条。sql语句如下: select sum(b.money) as '金额' from (select

1.有的时候,在数据库中存在一些重复的数据,但是我们又想统计某个字段的值,重复的要剔除掉,如图所示:

sql server 统计数据库中某个字段的值,剔除重复数据和查找重复

在上面的图我们可以看到,id=2,3 id=4,5的4条数据都重复了,我们统计amount只要其中的一条。sql语句如下:

select  sum(b.money) as '金额' from (select MAX(amount) as money from test   group by name) b

2.查找重复的数据

sql server 统计数据库中某个字段的值,剔除重复数据和查找重复

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn