Вопрос

I want to write a SELECT command that the Space character was not important.

for example

My data
-------
AB DE
A EFF
A E F E
ABC DEF

And my answer should be this:

AB DE
A EFF
A E F E

it means "I want all the 4length word that start with 'A' and the space character is not important".

How can I write this SELECT command???

Это было полезно?

Решение

You can split the condition in two, one for starting with A and one for the length.
You can use REPLACE to remove the spaces and just check the length of the remaining characters.

SELECT * 
FROM mytable
WHERE mydata LIKE 'A%'
 AND LENGTH(REPLACE(mydata, ' ', '')) = 4;

An SQLfiddle to test with.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top