sql根据某一个字段重复只取第一条数据,像我们这里 只考虑手机重复,要是手机重复,我们只取第一条记录。不考虑圈红色部分最后一个字段不一样,怎么解决?
哪位好心人帮忙下嘿
亲,其实这里是要针对Excel 表导入进行过滤的(Excel表导入到SQL数据库的表已经写在asp.net方法里辣),Excel表导入到sql中间表这里要过滤,其实也就是要写访问Excel的sql过滤语句,然后添加到sql表中
代码如下:
select * from tbl_DPImg where ID in (select min(ID) from tbl_DPImg group by DPID)
处理后结果为:
查找表中多余的重复记录,重复记录是根据单个字段(teamId)来判断
select * from team where teamId in (select teamId from team group by teamId having count(teamId) > 1)
删除表中多余的重复记录,重复记录是根据单个字段(teamId)来判断,只留有rowid最小的记录
delete from team where
teamName in(select teamName from team group by teamName having count(teamName) > 1)
and teamId not in (select min(teamId) from team group by teamName having count(teamName)>1)
扩展资料
数据记录筛选:
sql="select * from 数据表 where字段名=字段值 order by字段名[desc]"(按某个字段值降序排列。默认升序ASC)
sql="select * from 数据表 where字段名like '%字段值%' order by 字段名 [desc]"
sql="select top 10 * from 数据表 where字段名=字段值 order by 字段名 [desc]"
sql="select top 10 * from 数据表 order by 字段名 [desc]"
sql="select * from 数据表 where字段名in ('值1','值2','值3')"
sql="select * from 数据表 where字段名between 值1 and 值2"
参考资料来源:百度百科:SQL语句大全
使用分析函数row_number() over (partiion by ... order by ...)来进行分组编号,然后取分组标号值为1的记录即可。目前主流的数据库都有支持分析函数,很好用。
其中,partition by 是指定按哪些字段进行分组,这些字段值相同的记录将在一起编号;order by则是指定在同一组中进行编号时是按照怎样的顺序。
示例(SQL Server 2005或以上适用):
select s.*亲,你太厉害了!!!这些对于sql的表完全没有问题,但是要是用在Excel 表上会出错
追答Excel好像不能支持的,它不是实际意义上的数据库。就连SQL Server也是2005开始有支持分析函数的。
如果是Excel那么要使用Excel的方式来解决。
还是很感谢你!!!
本回答被提问者和网友采纳亲,这个有点难,技术水平有限
追答总体思路就是 把每个 手机号取第一条数据放入临时表,最后查询临时表
但是我得整条数据啊
select distinct (手机号) 只能取到‘手机号’这个字段而已啊
你!!!你在字段后面加其他字段呀,select distinct (手机号),电话 你想要什么字段就加多少字段