英文:
SQL order by part of string (Postgresql)
问题
I need some help with SQL sort query creation. I have data like
ref_num
24534535_R
11789999_S
34543049_S
23476243_R
45737458_S
I need to sort that data based on the last string (R first, then S)
How to sort it using postgresql?
I tried using substring and still not work
需要根据最后的字符串排序数据(首先是R,然后是S)。在PostgreSQL中如何进行排序?我尝试使用substring但仍然无法正常工作。
英文:
I need some help with SQL sort query creation. I have data like
ref_num
24534535_R
11789999_S
34543049_S
23476243_R
45737458_S
I need to sort that data based on the last string (R first, then S)
How to sort it using postgresql?
I tried using substring and still not work
答案1
得分: 1
你应该能够使用 right(string text, n integer) → text
:
select * from some_table order by right(ref_num, 1);
英文:
You should be able to use right(string text, n integer) → text
:
select * from some_table order by right(ref_num, 1);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论