Since this is a draw where there is no repetition of values in the columns, you can use the operator IN
:
SELECT
COUNT(*)
FROM
sorteiosanteriores
WHERE
20 IN (bola1,bola2,bola3,bola4,bola5,bola6 ... bola15)
See working on SQL FIDDLE.
Now, you need to see if this "horizontal" modeling is the best solution. Probably a related table is better than a lot of columns for the same purpose.
Attention: this query was optimized for the case of "Easy", and counts the number of lines that the 20 is returned, regardless of whether it occurred once or several times on the same line. For general count, see @Mauroalmeida’s reply or the following excerpt.
Counting multiple occurrences
SELECT
SUM((bola1=20)+(bola2=20)+(bola3=20)+ ... +(bola15=20))
AS quantidade
FROM
sorteiosanteriores
See working on SQL FIDDLE.
This works in a very simple way. The true
in Mysql has value 1, and false
0. Thus, just add the amount of equalities per line, and add with SUM
.
This second option counts the total number of occurrences, including repetitions on the same line.
Could show your failed tests and a return of the result of this example that shows?
– MauroAlmeida
'code'SELECT COUNT(18) FROM
sorteiosanteriores
'code was the first one that resulted in the count informing the data contained in the date field. Another attempt was 'code'SELECT COUNT(*) FROMsorteiosanteriores
WHERE Bola1 = 18 AND Bola2 = 18'code' returning zero– Fabio Ozuna