Display only landline and mobile phones with type 9 in front

Asked

Viewed 401 times

-1

Following

I have a table called telefonia_numero and within it is a field called Numero where contains all user phone.

Ex . Jose - Number 81 3636-1145, 81 99873-7787 and 9873-7787,

Here comes what I want.

I want to take only the landline and the cell phone with type 9 in front ex. ( 81 99873-7787). And would be out what a nine the menus in front of Ex (9873-7787) then pick up the landline and the new phones with type 9 on the front.

  • 1

    The phones in this field are comma separated? which database are you using?

  • The phones are this way 81 3636-1145

  • and the data set phpmyadmim and are not separated with comma no

1 answer

0

You can use the functions replace() and char_length() Mysql to subuse the blank space for nothing and count the number of characters in your phone and check if it has 11 digits in the WHERE thus:

//O primeiro parênteses verifica se é celular
SELECT * FROM telefones
WHERE (substr(replace(telefone, ' ', ''), 3,1) = 9 AND
CHAR_LENGTH(REPLACE(telefone, ' ', '')) = 12) OR CHAR_LENGTH(REPLACE(telefone, ' ', '')) = 11
  • rray this select be bringing the fixed number 81 3636-1145 with 11 characters and mobile phones that has 11 characters 81 9873-8878. so I want to appear fixed with 11 characters ex 81 3636 - 1145 and mobile phones with 12 characters ex 81 99873-8878.

  • @user42804 the space is not being removed? the query should do this. vc have some field that identifies whether the phone is mobile or fixed? change = for >= resolves?

  • has not even a field that identifies whether it is cellular or fixed!

  • @user42804 changed the answer see if this answers.

  • rray friend - still bringing the old cell phones ex 81 9873-8878. however it is only to bring fixed ex 81 3636-1145 and cell phones that has digit nine in front ex 81 99873-8878. I stand by and thank you in advance

Browser other questions tagged

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