473,493 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to sort days in oracle

29 New Member
help me with this, i need to sort the order to be like sun,mon,tue,wed,thu,fri,sat
Sep 11 '08 #1
6 8394
r035198x
13,262 MVP
You need to give more details than that to get help.
Sep 11 '08 #2
rahulae
29 New Member
i have to write a query in such a way i have to get no of employees joined on a particular day.

i have written the following query

select count(*)"no of emp joined",to_char(hiredate,'day') "day" from emp group by to_char(hiredate,'day');

output:
no of emp joined day
2 friday
1 monday
2 saturday
2 sunday
3 thursday
3 tuesday
1 wednesday

but i want the days to be sorted in order starting from sun,mon,tue,wed,thu,fri,sat
Sep 11 '08 #3
r035198x
13,262 MVP
For any arbitrary order sorting, check out amit's post in this thread.
Sep 11 '08 #4
N002213F
39 New Member
the hard and long way;

Expand|Select|Wrap|Line Numbers
  1. select
  2.     count(*) as NO_EMP_JOINED,
  3.     to_char(hiredate,'day') AS DAY_OF_WEEK,
  4.     (case when DAY_OF_WEEK = 'Sunday' then 1 
  5.          when DAY_OF_WEEK = 'Monday' then 2
  6.          when DAY_OF_WEEK = 'Tuesday' then 3
  7.          when DAY_OF_WEEK = 'Wednesday' then 4
  8.          when DAY_OF_WEEK = 'Thursday' then 5
  9.          when DAY_OF_WEEK = 'Friday' then 6
  10.          when DAY_OF_WEEK = 'Saturday' then 7
  11.          else 99 
  12.       end) AS ORDERCOLUMN
  13. from emp 
  14. group by to_char(hiredate,'day')
  15. order by ORDERCOLUMN
  16.  
and the easy way, Oracle saw you coming;

http://www.techonthenet.com/oracle/f...ns/to_char.php

check right at the bottom of the page and the question.
Sep 11 '08 #5
N002213F
39 New Member
Expand|Select|Wrap|Line Numbers
  1. select
  2.     count(*) as NO_EMP_JOINED,
  3.     to_char(hiredate,'day') AS DAY_OF_WEEK
  4. from emp 
  5. group by to_char(hiredate,'day')
  6. order by decode(upper(substr(DAY_OF_WEEK, 1,2)), 'SU', 0, 'MO', 1, 'TU', 2,'WE', 3,'TH', 4,'FR', 5,'SA', 6, 99)
  7.  
based on http://bytes.com/forum/thread823124.html
Sep 11 '08 #6
rahulae
29 New Member
Thanx for ur help it works
Sep 11 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3196
by: One's Too Many | last post by:
Ran into a strange problem today: 8.1.7 on AIX 4.3.3 Database and applications had been working fine for two years and all of a sudden a couple of regularly-run queries are now no longer...
0
1756
by: Steve Wells | last post by:
Hi, We need an Oracle expert to help us convert a SQL appication to Oracle for a particuler project we're working on. We have all the stored procs., etc. already converted, we're just having...
6
22506
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm raid 5 on u320 perc raid...
20
4019
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
11
3874
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
1
1382
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
4
8572
by: tbramley | last post by:
Hi, I've got a cross tab query which is sorted by area then month but the month is sorted in alphabetical order and I was wondering if this can be done in Month order e.g. April, May, June, July...
1
2115
by: Prosdo | last post by:
Hi guys. I have a final program for school and the assignment is to show the top 5 numbers for the Cash 5 lottery over the past few days. I think I have all my loops right.I think I have the output...
1
2772
by: chevyas123 | last post by:
How do i write a function to calculate business days excluding weekends and holidays in oracle? Actually i need to prepare a calendar for my monthly activities i.e activity x to be performed on 3rd...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.