Skip to Content
0
Former Member
May 31, 2016 at 11:30 AM

Order by in Union all

1423 Views

Hello,

How to use two columns in order by while using UNION ALL in a query in SBO HANA database

I am trying to get the list of all sales made in the company.

Please check and revert with the query. thanks in advance

Regards,

JK Prabhu

SELECT 'Inv' as "Type", YEAR(T0."DocDate"), T1."Dscription" "Chemical", T0."CardName" "Customer", SUM(T1."Quantity") "Quantity", T1."unitMsr", SUM(T1."LineTotal") "Value" FROM OINV T0 INNER JOIN INV1 T1 ON T0."DocEntry" = T1."DocEntry" INNER JOIN OCRD T2 ON T0."CardCode" = T2."CardCode" WHERE T0."CANCELED" = 'N' GROUP BY YEAR(T0."DocDate"), T1."Dscription", T0."CardName", T1."unitMsr"

UNION ALL

SELECT 'CN' "Type", YEAR(T0."DocDate"), T1."Dscription" "Chemical", T0."CardName" "Customer", SUM(T1."Quantity") "Quantity", T1."unitMsr", -SUM(T1."LineTotal") "Value" FROM ORIN T0 INNER JOIN RIN1 T1 ON T0."DocEntry" = T1."DocEntry" INNER JOIN OCRD T2 ON T0."CardCode" = T2."CardCode" WHERE T0."CANCELED" = 'N' GROUP BY YEAR(T0."DocDate"), T1."Dscription", T0."CardName", T1."unitMsr"

ORDER BY YEAR(T0."DocDate")

In this query i want to sort by the two columns:- YEAR(T0."DocDate"), T1."Dscription"