用sql过滤重复记录,遇到一个问题需要过滤某一个字段的值重复的记录,但要取一条出来。只有一个字段值是重复的,其它字段值不重复。我用这样的语句来做Select * From [tb_SurveyData] where Sd_Id in (select max(Sd_Id) as Sd_Idd from [tb_SurveyData] group by Sd_Ip) And Sd_Sid=@Sd_Sid可以复到的结果不是我想要的,似乎每次只得到一个结果。为什么?
解决方案 »
- 单位要我开发上位机软件 串口通讯 懂的朋友进来帮我下
- 收藏 100分!!!VB.NET调用无返回值的存储过程!!
- datagridview跳转到指定行问题
- 怎么给在datagridview里面的DataGridViewComboBoxColumn设置SelectedIndexChanged事件?
- 想知道各种数据文件的存储量是多少?
- 水晶报表不同电脑打印出的不同情况,在线等....
- c#下一个类中怎样声明一个结构体数组???
- 关于音频流的问题
- 关于datagrid中的记录选定
- 用Application.StartupPath可以得到应用程序启动的目录,但是如何项目是一个dll类库,如何知道启动路径?
- Linq问题--->有想法的高人进
- .net调用EMPP 组件问题
查看Sql帮助.
select * from [tb_SurveyData] where Sd_Id in (select distinct Sd_Id from [tb_SurveyData] group by Sd_Ip)
create table table1 (id int, ip varchar(15))
insert table1
select 1, '127.0.0.1' union
select 2, '127.0.0.2' union
select 3, '127.0.0.2' union
select 4, '127.0.0.3' union
select 5, '127.0.0.3' union
select 6, '127.0.0.4' union
select 7, '127.0.0.4' -- 查询
select * from table1 where id in -- 检索重复ip的纪录
(select min(id) from table1 where ip in -- 求重复ip的其中一个id
(select ip from table1 group by ip having count(1) > 1) -- 取出重复的ip
group by ip
)drop table table1
insert table1
select 1, '127.0.0.1' union
select 2, '127.0.0.2' union
select 3, '127.0.0.2' union
select 4, '127.0.0.3' union
select 5, '127.0.0.3' union
select 6, '127.0.0.4' union
select 7, '127.0.0.4' -- 查询
select distinct(ip) from table1drop table table1
数据表 where 条件语句)
数据表 where 判断最大值的列名 in(select max(判断最大值的列名 ) from 数据表 where 条件))