按列和字母顺序排序(如果为null或零)

jjhzyzn0  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(461)

我有一个要求,以invqty之和的升序获得invqty列之和,我的查询完成。但在某些情况下,invqty之和为0或null,在这种情况下,我需要customer列按字母顺序升序排列。
我如何做到这一点?
我正在使用hana数据库。

SELECT CUSTOMER AS CUSTOMER,
SUM(INVQTY) AS INVQTY
FROM TEST_TABLE
GROUP BY CUSTOMER
ORDER BY INVQTY

数据示例:

CUSTOMER   INVQTY
A          0
B          10
B          20
C          0

当前结果:

CUSTOMER   INVQTY
C          0
A          0
B          30

预期结果:

CUSTOMER   INVQTY
A          0
C          0
B          30
rta7y2nd

rta7y2nd1#

你需要两列 ORDER BY 具体如下:

SELECT CUSTOMER AS CUSTOMER,
SUM(INVQTY) AS INVQTY
FROM TEST_TABLE
GROUP BY CUSTOMER
ORDER BY INVQTY, CUSTOMER

相关问题