将重复的记录合并到具有相同表格和表格字段的1条记录中 [英] Merge duplicate records into 1 records with the same table and table fields

查看:107
本文介绍了将重复的记录合并到具有相同表格和表格字段的1条记录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含人口统计记录列表的数据库表,其中一些参与者可能有多个/重复记录,例如



注意:

性别:

119 =男性

118 =女性

种族:

255 =白色

253 =亚洲


UrbanRural:

331 =城市

332 =农村


 参与式,性别,种族,urbanrural,moduletypeid,hibernateid和更多字段
1,119,0,331,1,1,.....
1,119,255,0, 1,2,...,
1,0,25,331,3,3,.....
1,119,253,331,0,4,.... 。

输出应该保留第一个hibernateid,重复记录将合并到第一个hibernatedid记录。如果您可以使用函数来执行此操作,该函数将检查记录是否重复,那么合并记录后会删除未使用的重复记录。你的回答给了我一个解决这个问题的好主意。感谢

输出应该是:

 参与式,性别,种族, cityrural,moduletypeid,hibernateid和更多字段
1,119,255,331,1,1,.....



帮助我们,谢谢

解决方案



  select参数化,min(性别),min(race),min(urbanrural),
min(case moduletypeid当0 then null else moduletypeid end),min(hibernateid),...
from yourtable
group by参数化

我不清楚为什么在你的例子中moduletypeid应该返回为1 - 我假设这个字段中的0是一个特殊情况,被视为null(因此是case子句)。

I have a database table that contains a list of demographic records, some of those participant might have multiple/duplicate records, e.g.

NOTE:
Gender:
119 = Male
118 = Female

Race:
255 = white
253 = Asian

UrbanRural:
331 = Urban
332 = Rural

participantid, gender, race, urbanrural, moduletypeid, hibernateid, and more fields
1, 119, 0, 331, 1, 1, .....
1, 119, 255, 0, 2, 2, .....
1, 0, 255, 331, 3, 3, .....
1, 119, 253, 331, 0, 4, .....

The output should be keep the first hibernateid and the duplicate records will be merge to the first hibernatedid record. If you can do this using function that will check the records if duplicate that would be great, after merged the records it delete the unused duplicate records. Your answer gives me a great idea to resolved this problem. Thanks

Output should be:

participantid, gender, race, urbanrural, moduletypeid, hibernateid, and more fields
1, 119, 255, 331, 1, 1, .....


Help me guys, Thanks

解决方案

Try something like:

select participantid, min(gender), min(race), min(urbanrural), 
min(case moduletypeid when 0 then null else moduletypeid end), min(hibernateid), ...
from yourtable
group by participantid

It's not clear to me why moduletypeid whould be returned as 1 in your example - I have assumed that 0 in this field is a special case, to be treated as null (hence the case clause).

这篇关于将重复的记录合并到具有相同表格和表格字段的1条记录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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