Skip to content
Advertisement

How To Find Perfect Match With Multiple Rows Across Tables?

I’m looking for a way to find out which collection of lines from #Orders matches with #Pallets the best.

With the example below with @palletId = 1000 as input to the query the results should only be able to match with ‘Order2’ (100% match) and ‘Order4’ (75% match). In this case my desired result would be ‘Order2’.

Input @palletId = 4000 should have a 100% match to ‘Order4’ and no other matches.

Been trying to solve it using the following examples as bases but haven’t managed to get the result that I want.

https://stackoverflow.com/a/27060384/2975371

https://stackoverflow.com/a/104001/2975371

Thanks in advance.

Advertisement

Answer

You can try something like a

I just took difference between those two to figure out which one is ‘close’ to 100%. abs(@cnt - count(PalletId)) will only return zero if there is a 100% match

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement