Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL - Grouping

Status
Not open for further replies.

SQLMeToo

Technical User
Apr 10, 2000
12
0
0
AU
I have query, grouping data by hour using<br>Group by DatePart(hour, TheDateField)<br><br>I need to group records by the half hour - <br>I cant use: Group by DatePart(minute,The DateField)<br><br>Has anyone got a suggestion.<br><br>regards
 
Oracle solution:<br>You can use a column like:<br><b>DECODE sign(TO_NUMBER(TO_CHAR(TheDateField,'MIN'))-30,1,'To','Past')</b>, combined with the column which extracts the hour. So you get 2 columns for the <b>group by</b> clause. Of course, using aq more complicated formula you can combine those 2 columns in a single one, but you can try my solution. <p>Eduard Stoleru<br><a href=mailto:e_stoleru@yahoo.com>e_stoleru@yahoo.com</a><br><a href= > </a><br>
 
Sorry, I'm correcting my answer. You should read:<b><br>DECODE(sign(TO_NUMBER(TO_CHAR(TheDateField,'MI'))-30),1,'To','Past')</b>. So, you can get 'To' value for minutes in 31..59, 'Past value for minutes in 0..30. If you want other partition, you can alter the DECODE statement like <b>DECODE(sign(TO_NUMBER(TO_CHAR(TheDateField,'MI'))-30),1,'To',-1,'Past','Half')</b> <p>Eduard Stoleru<br><a href=mailto:e_stoleru@yahoo.com>e_stoleru@yahoo.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top