Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 9th, 2003, 03:34 PM
black_lotus black_lotus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 241 black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 12 h 11 m 42 sec
Reputation Power: 19
order by, group by question

Hi,

I have this query that I need to refine a little but am unsure how to do it. Basicall i need to sort it a specific way and I cam across a resultset that gave me problems. The best way to describe the problem is to show u the resultset that gave me problems:

productid classid type age
5000       12       A     30
5000       12       A     30
5000       12       A     31
5000       12       A     31

this query will is ordered by 1,2,4 (and normally the resultset wont all have the same productid and classid, but in this case it does). What i need is to have the age be 30, 31, 30,31. Can this be done by a group by clause? I'm not very familiar with it, can u post some code.
Thanks

Reply With Quote
  #2  
Old December 9th, 2003, 09:11 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,690 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 16 h 20 m
Reputation Power: 985
for the specific example you have shown, no it cannot be done

with all the other columns being equal, you are basically left with only two ORDER BY options for the age column: ascending or descending

there is no ORDER BY alternating

rudy
http://r937.com/

Reply With Quote
  #3  
Old December 9th, 2003, 09:47 PM
black_lotus black_lotus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 241 black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 12 h 11 m 42 sec
Reputation Power: 19
And there is no GROUP BY clause that will work?

Thanks

Reply With Quote
  #4  
Old December 9th, 2003, 09:52 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,690 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 16 h 20 m
Reputation Power: 985
i'm pretty sure there isn't, although if you give a more realistic example...

Reply With Quote
  #5  
Old December 10th, 2003, 08:52 AM
black_lotus black_lotus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 241 black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 12 h 11 m 42 sec
Reputation Power: 19
Thats as realistic as I can get for this one because this is exactly what my resultset is.

Thanks

Reply With Quote
  #6  
Old December 10th, 2003, 11:53 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,690 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 16 h 20 m
Reputation Power: 985
well, if we weren't talking about sql, but rather in plain english, how would you describe sorting 27, 28, 28, 29, 29, 30, 31, 31?

what sequence would you like those in?

i mean, your unusual sequencing (alternating?) just ain't gonna happen with a simple ORDER BY

sorry, but please don't shoot the messenger


Reply With Quote
  #7  
Old December 10th, 2003, 02:22 PM
black_lotus black_lotus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 241 black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level)black_lotus User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 12 h 11 m 42 sec
Reputation Power: 19
Sorry, perhaps i should have mentioned that there will never be more than 2 different ages(ie: it will never be 28,28,29,29,30,30..)
Only two ages.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > order by, group by question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway