I wounder if its possible to find out using sql the most frequent pairs of numbers which appear in the table. ie:
I’ve got few columns populated with numbers:
num1, num2, num3, num4, num5, num6
2 3 4 5 6 7
Of course the number of rows is larger but you got an idea..
The goal is to display for example 10 pairs of numbers which appeared in rows.
Please let me know if its possible, or I should rather perform a “brute-force” kind of solution.
Regards
In order to solve this problem, you need to do the following:
Let me give a solution that will work in SQL Server, and with very minor modifications in mysql:
I don’t think mysql supports the “with” syntax, so you need to either repeat the subquery twice, put the results in a temporary table, or create a view.
You can also express the same idea with database specific constructs, such as “unpivot” in SQL Server. This can somewhat simplify the SQL, but not by much.
If you don’t have a unique id for each row, then an easy thing to do in SQL Server is to use the row_number() function to assign one, in another “with” statement. Alternatively, you could possibly just convert all the numbers to character strings and then concatenate them together.