统计时,相同的数据只算一条数据,怎么写sql

来源:百度知道 编辑:UC知道 时间:2024/06/04 15:39:08

如果ID不同 其他相同用
select * from table where id in(select max(id) from table group by 字段1,字段2......)

试试

如果ID也相同 用
select distinct id,字段1,字段2......from table

至于统计算法你没说 自己写吧

select COUNT(DISTINCT [field_name] ) from tablename

其中[field_name] 你要统计的字段 这种解答是正确的

select COUNT(DISTINCT [field_name] ) from tablename

其中[field_name] 你要统计的字段

select distinct id,name
from table