Problem with ORDER BY sorting when using CASE WHEN in TiDB

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb使用case when的时候order by排序出现问题

| username: Jjjjayson_zeng

【TiDB Usage Environment】Production Environment
【TiDB Version】
【Reproduction Path】Incorrect sorting
【Encountered Problem: Problem Phenomenon and Impact】
【Resource Configuration】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots/Logs/Monitoring】


image
image

| username: Kongdom | Original post link

Try changing else '' to else 0.

| username: tidb菜鸟一只 | Original post link

Obviously treated as a string.

| username: zhanggame1 | Original post link

else ‘’ This is a problem ‘’ is not null

Change the else part to 0 or null

| username: Jjjjayson_zeng | Original post link

Indeed, it is this issue. Thank you.

| username: Kongdom | Original post link

:handshake: :handshake: :handshake:

| username: redgame | Original post link

Indeed, this is the issue.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.