سؤال

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