Order by 1

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Order by 1
# 1  
Old 09-10-2016
Order by 1

Code:
select to_char(cre_on, 'ddmm hh24'), proc_flg, count(*) from ib_prd.tb_ibmh_msg_log where message_type = 'DECHECK_OUT'
and cre_on > to_date('27/08/2016 00:00:00', 'dd/MM/yyyy hh24:mi:ss')
group by to_char(cre_on, 'ddmm hh24'), proc_flg
order by 1;


1) what does order by 1 means
2) group by is by column name, can't i use cre_on as the parameter, why need to convert to 'ddmm hh24'

Last edited by vbe; 09-29-2016 at 04:41 PM.. Reason: reverted to original
# 2  
Old 09-10-2016
The simple answer: SQL has syntax rules
#1:
order by 1 == order by the first field in the selected resultset
namely: to_char(cre_on, 'ddmm hh24') which is a character conversion that represents the internal oracle date datatype which humans cannot read easily. It is an octaword of the number of seconds elapsed since Julian day 1
Quote:
[Julian calendar] assigns a Julian Day (JD) to every year without having to worry about B.C.E or C.E. It was invented by French Scholar Joseph Justus Scaliger in 1583, who proposed that the Julian Period starts at noon on January 1, 4713 B.C.E. (in the old roman Julian calendar) and lasts for 7980 years.
#2:
You cannot group by a column that does not exist. Your resultset has what datatype? character. You want to use the oracle date datatype. Will not be accepted.

As a side note
to_date('27/08/2016 00:00:00', 'dd/MM/yyyy hh24:mi:ss')
may result in poor performance because versions of oracle before 11g may not use an index when the field referenced is defined by a function call -- to_date - in this case. If an index on that column exists of course.
This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Re-order columns

I am trying to reorder columns based on a value in a field in the attached file. Thank you :). If $11 is not equal to "unknown", then in a new text file $4, $11, $7, $13 For example, row 24 $11 is not unknown A_16_P39089234, chr10:76765556-76765615, KAT6B, 0.9337 (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

Increasing order

Hi , I have around 1000000 odd lines in a file in random order. The file looks like this: >string102 >string10437183 >string514 >string10435771 >string10437259 >string1049931 >string1342 I want to arrange it in increasing order: >string102 >string514 >string1342... (3 Replies)
Discussion started by: qwerty193
3 Replies

3. Shell Programming and Scripting

change order

I have inside a file 22 25 80 111 631 694 861 875 I need this in the form using awk or sed 22,25,80,111,631,694,861,875 (4 Replies)
Discussion started by: anil510
4 Replies

4. Shell Programming and Scripting

Column not in order

Hi, I was trying to have an output as below : 1 | 2 | 3 aaa | bbb | ccc | ccc | ccc ... (2 Replies)
Discussion started by: scottralf
2 Replies

5. Shell Programming and Scripting

Ascending order

How can I check if array is in ascending order? ---------- Post updated at 01:53 PM ---------- Previous update was at 01:25 PM ---------- Done it now (0 Replies)
Discussion started by: kristinu
0 Replies

6. Ubuntu

Boot order?

Hi I have Ubuntu 10.10 installed. I want to change boot order. Can anyone tell where is menu.lst file located. I searched it but didn't get it. Please tell me what file I need to edit for same? (3 Replies)
Discussion started by: nixhead
3 Replies

7. Shell Programming and Scripting

Change order

Good evening I have a file as below and want to change the order, as in the second column, sed awk Pearl Thanks aaaaaaaaaa bbbbbbbbb cccccccc aaaaaaaaaa bbbbbbbbb cccccccc aaaaaaaaaa cccccccc bbbbbbbbb aaaaaaaaaa cccccccc bbbbbbbbb (8 Replies)
Discussion started by: Novice-
8 Replies

8. UNIX for Dummies Questions & Answers

order by size

Hi all, I want to do a command that list all files from a directory e subdirectories order by size (MAX to MIN) Can you help me? Tkz (2 Replies)
Discussion started by: sliver
2 Replies

9. UNIX for Dummies Questions & Answers

Order sorting

How do you sort text in order using sed? :confused: For example 01 B D A C to 01 ABCD (3 Replies)
Discussion started by: evoGage
3 Replies

10. AIX

Where to Order 5.1L Cds

Anyone know where you can purchase a 5.1 cd set? IBM no longer ships this out and do not have a set. I have a burned copy, but would be nice to have the originals. I'd like to send my copies offsite for DR once i get an original set. Thanks! (2 Replies)
Discussion started by: slacker
2 Replies
Login or Register to Ask a Question