mardi 4 août 2015

calculate lowesr differents between 5 cells to other 5 cells

I have this row - [11,19,59,69,9] lets call it FIRST and i have another ~ 100 million rows with the same format

[10,20,30,20,50],
[15,50,60,70,10]
...
...

I need to compare each number from FIRST row to each number in the corresponding cell in each row from the 100M rows , and take the abs diff between those two values and sum all of the diff.

Example :

FIRST - [11,19,59,69,9]
row   - [10,20,30,20,50]
diff  - [|11-10|,|19-20|,|59-30|,|69-20|,|9-50|]  = [1,1,29,49,41] 
sum(diff) = 1+1+29+49+41 =121

And i need to do this comparison between the FIRST and the rest of the rows and output the row with the smallest diff.

What is the best way to do it ? I need to implement it on my SQL DATABASE . Maybe there is SQL query for this ? or maybe i should develop some inner function via c, or c++?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire