Order by issue in PrestoDB

Hello,

I am using Presto with Helical Insight 4.0. When I have distinct function applied on the columns, order by or sorting does not work and generates incorrect SQL. Below is a snapshot of the output and also the SQL query that is generated. Please help correct this issue.
image

The SQL produced is as below:

**select**  

        "Distinct_Visitors"."browser"  **as**  "Browsers",

       "Distinct_Visitors"."distinct_visitors"  **as**  "Distinct Visitors" ,dense_rank()  over( **order**   **by**  "Distinct_Visitors"."browser"  **asc**  )  **as**  rownum 

**from**  (

        **select**

             count( **distinct**  visitorid)  **as**  distinct_visitors,

             browser  **from**  hive.matomo_demo_prod.dive_zone_dataset  **group**   **by** browser

     )  "Distinct_Visitors"

**order**   **by**

        "Browsers",

        "Distinct Visitors"

**asc**

Thank You

1 Like

Hello Tarun,

The js file for the database in the sqlFunctions folder is responsible for generation of correct SQL queries.

Please download this presto.js file and place it in the location

…/hi/hi-repository/System/Admin/SqlFunctions/

After this, clear the cache and try in a private window to see the result. The output will have sorting working in the correct manner for the report.

image
Thank You
From Team Helical