prime numbers from 0 to 10 in mysql

Asked

Viewed 448 times

1

Good afternoon, I’m having trouble with this Mysql question:

Show the name of the animals and the breed code. Just show the animals that contain in their respective code a prime number from 0 to 10.

I tried with the following code:

SELECT nome, raca from animais where 
(codigo > 0 and codigo < 10)
and (codigo % 1 = 0 and codigo % 2 = 0) or (codigo % 1 = 0 and codigo % 3 = 0) or 
(codigo % 1 = 0 and codigo % 5 = 0) or (codigo % 1 = 0 and codigo % 7 = 0)

Makes the following mistake, only:

Error = { Answer with Error }

Because I am solving questions of sqlweb.com.br. Following the image of the site with the question, the answer and the error:

inserir a descrição da imagem aqui

  • Edit the question with the error generated.

  • 3

    Tip: your verification can be simplified to codigo in (2, 3, 5, 7), because you know that those are the prime numbers between 0 and 10 - and that won’t change anytime soon.

  • The "contain" of the statement is ambiguous. Worth codes that have a digit cousin?

  • @bfavaretto I understood that it is worth any code that has a prime digit, such as 34 enter, since 3 is prime. But it is very confusing.

  • in (2, 3, 5, 7) code gives error

  • 1

    Any number is divisible by 1 and therefore the rest of the division of any integer by 1 will always be zero.

Show 1 more comment

1 answer

-1

Since the prime numbers between 0 and 10 are few and it is a mathematical rule, that is, something exact, we can use the fixed code to verify if the number is prime:

Number of primes between 0 and 10: 2, 3, 5, 7

SELECT nome, raca 
  FROM animais 
 WHERE codigo in (2, 3, 5, 7) 
  • @João Ricardo, this should solve

  • No, keep giving error.. I am suspicious or that it is the site’s own error, or that I did not understand the question exactly.. In doubt I skipped the question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.