Home Forums SQL Server 2012 SQL Server 2012 - T-SQL How to compare a list of numbers, kind of like lottery results Reply To: How to compare a list of numbers, kind of like lottery results

  • wrote:

    Hey there!

    Each winning/drawn number has its own row, however you would probably unpivot the data in both tables so that you have a key for which group of numbers it belongs to. Then you connect the unpivoted tables for the first one, count the rows, and then you get a count of matches. In order to retrieve the row(s) with the most matches, you need to perform the same processes for each row of the winning numbers table for the second drawing, grouping them by a counted unique drawing identification.

    That's basically what most of the posts and a lot of the code on this thread suggests.  Have you some alternative code that you'd like to share?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)