Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
SAP HANA

Order by and Having additions in SQL

 

This tutorial is continued from the previous tutorial for Aggregate functions.

Pre-requisites: Go through the tutorial Aggregate functions.

This tutorial explains some of the additions that can be added to the SQL statements.

Order By:

Now if you look at the result set, The category is neither sorted in the ascending order or descending order. If you wanted to sort and display the result set then you can use the addition order by to the SQL Statement. By default the order of sorting is ascending. You can change it to descending by providing addition desc.

Query:

clip_image001

 

Result:

clip_image003

 

You can also group by , or order by ‘n’ no of columns. For example I wanted to sort the result set by Category and Product ID then the query is as below.

Query:

clip_image004

Result:

clip_image005

 

 

Having:

Having keyword specifies the conditions for the aggregate functions. In the previous examples we have seen the total unit of measure for product and their averages. Now say I wanted to perform the additional check that I wanted to display the Product category only when the sum of weightmeasure for that category is greater than 25.

Query:

clip_image006

 

Result:

clip_image007

 

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.