SQL Group By與Order By
阿新 • • 發佈:2019-01-03
SQL Group By與Order By
Group By的字面含義可以理解為分組,使用後可以根據 By 後面的欄位對數字進行彙總。
原表資料:
CLEAR GT_DATA[] .
SELECT
VBAP~VBELN
SUM( VBAP~KWMENG ) AS KWMENG
INTO CORRESPONDING
FROM VBAP
WHERE VBAP~VBELN IN ( '1000000327','1000000330' )
GROUP BY VBAP~VBELN
.
返回結果如下表,實際上就是按照單號對數量彙總。
而Order By
SELECT
VBAP~VBELN
SUM( VBAP~KWMENG ) AS KWMENG
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM VBAP
WHERE
GROUP BY VBAP~VBELN
ORDER BY KWMENG DESCENDING
.