简体   繁体   English

有没有办法使用sql获取最佳记录

[英]Is there a way to take the best records using sql

In a database with million of records, would it be a possible way to take the best records (ie. rows with the most populated columns)在具有数百万条记录的数据库中,是否有可能采用最佳记录(即具有最多填充列的行)

SEQ_ID | PERSON_ID | GENDER | DOB        | COUNTRY
1      |  A000001  |  Male  | 01-01-1970 | 
2      |  A000001  |        |            | Indonesia

Would it be possible to take the 2 Records to combine it into 1?是否可以将 2 条记录合并为 1 条记录? Eg例如

SEQ_ID | PERSON_ID | GENDER | DOB        | COUNTRY
1      |  A000001  |  Male  | 01-01-1970 | Indonesia

With your example, you can use aggregation:在您的示例中,您可以使用聚合:

select MIN(SEQ_ID), PERSON_ID, MAX(GENDER), MAX(DOB), MAX(COUNTRY)
from t
group by PERSON_ID;

It is not clear if this will work generally on your data, but this does answer the question that you asked.目前尚不清楚这是否适用于您的数据,但这确实回答了您提出的问题。 If this doesn't work, you should ask a new question, with more appropriate data and explanation of the logic you want to use.如果这不起作用,您应该提出一个问题,提供更合适的数据和对您要使用的逻辑的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM