I'm having some trouble with translating the following SQL query for better reading in eloquent:
SELECT @number tested_number, 7 - LENGTH(nums.num) common_digits, tickets.*
FROM tickets
JOIN (SELECT 1 num UNION
SELECT 10 UNION
SELECT 100 UNION
SELECT 1000 UNION
SELECT 10000 UNION
SELECT 100000) nums
WHERE @number DIV nums.num = tickets.ticketNumber DIV nums.num
ORDER BY nums.num LIMIT 1;
I've a table with the attribute "ticketNumber" which is a string (6) like 123456
the query selects all tickets starting with the same chars (= @number)
e.g.
133333 is in common_digits 1
122222 is in common_digits 2
123222 is in common_digits 3
...
123455 is in common_digits 5
023456 has no common_digits
I wanted to implement this logic with this query. It has only two problems:
e.g. 123455 is in common_digits 1,2,3,4 and 5 instead of only common_digits 5
not able to use it in Laravel :D (even with raw query @vincent15000 )
maybe you have a better idea to solve this problem?