开发者

What is the best way to segregate the data alphabetically using SQL?

开发者 https://www.devze.com 2023-03-20 20:08 出处:网络
What is the be开发者_开发知识库st way to segregate the data alphabetically using SQL? I would like to divide the data into 3 parts based on starting character of data in some columns??You can use REG

What is the be开发者_开发知识库st way to segregate the data alphabetically using SQL?

I would like to divide the data into 3 parts based on starting character of data in some columns??


You can use REGEX_LIKE statement to get the result.

Example:

-- For Range [A--G]
SELECT target_col
FROM   target_table
WHERE  REGEXP_LIKE( target_col, '^[A-G].$' ) ;

-- For Range [H--O]
SELECT target_col
FROM   target_table
WHERE  REGEXP_LIKE( target_col, '^[H-O].$' ) ;

-- For Range [P--Z]
SELECT target_col
FROM   target_table
WHERE  REGEXP_LIKE( target_col, '^[P-Z].$' ) ;


-- For Range [A--G]

SELECT target_col
FROM   target_table
WHERE  target_col >= 'A'
  AND  target_col < 'H'

If there is a simple index on target_col, the query will probably use it.


Also you can use this:

select *
from your_table
where your_column between 'A' and 'G';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号