Skip to content
Advertisement

query range on column [closed]

I need help on query where I can do the range query based on Name Column from names.
e.g., as shown in sample data
starting from ‘A% to ‘C%’
and
from ‘a% to ‘c%’
and then from ‘D%’ to ‘F%’
and from ‘d%’ and ‘f%’

I need to split Name Column in 2 separate category which is from A to C and from D to F including all names with upper & lower case.

I tried with >=, <= and between, but it didn’t help.

Sample Data

Advertisement

Answer

You can use regex to achieve that. Try below query

select Name,(case when name like '[A-Na-n]%' then 'Category A-N' when name like '[O-Zo-z]%' then 'Category O-Z' end)Category from names where name like '[A-Za-z]%'

Output: enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement