Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Random order by in SQL!

Ryansun-OracleJun 19 2013 — edited Jun 19 2013

11g

Hi There,

  I had posted this query in the Application express forum, but I guess it really should have been posted in this forum, since its more of a sql question. Apologies if this is against the forum rules.

  We have a pie chart in Application Express which has select like

select null, '0-10' Days , count(*) from table

union

select null, '11-20' Days, count(*) from table

union

select null, '21-30' Days, count(*) from table

union

select null, '>30' Days, count(*) from table

The 3d pie chart was showing the slices is the correct order 0-10, 11-20, 21-30, >30 but now shows it in random order.

Unfortunately, the charts in Apex have a restriction as far as the select statement is concerned, it should just have three values in the select statement, the first is a link (can be null), the second can be any column_name or description and the third a value like count, sum etc. Now, the above query is to get the count of sales in the mentioned number of days and so what is happening is that it is taking the values as character sorting and I think randomly sorting in the apex chart. Now, this works fine in SQL! So was wondering if anyone has any suggestions on how to maybe force the sorting on the second column (0-10, 11-20 etc). If I take those values as 010, 1120, 2130 3000, something like that(basically a number) it seems to work fine, but then those show up as labels on the chart which is not correct.

Any suggestions on how to get the order by working. I suspect since the Days column in the select is a Character column this issue is occurring, however, with the restrictions in the number of select items we can have in the Apex charts, was wondering how do you get the order by working?

Thanks,

Ryan

This post has been answered by Ashu_Neo on Jun 19 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2013
Added on Jun 19 2013
9 comments
508 views