niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » IBM DB2
how to extract one row from each range data
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
janet
*nix forums beginner


Joined: 22 Feb 2005
Posts: 2

PostPosted: Fri Feb 25, 2005 2:22 am    Post subject: Re: how to extract one row from each range data Reply with quote

hi, Tonkuma

Thanks very much for quickly response! Both answered my question. The
second way is more flexible...


"Tonkuma" <tonkuma@jp.ibm.com> wrote in message news:<1109117294.910906.298150@g14g2000cwa.googlegroups.com>...
Quote:
------------------------------ Commands Entered
------------------------------
SELECT L, U, name, age, department
FROM (SELECT q.*, L, U
, ROWNUMBER() OVER(PARTITION BY L ORDER BY age) rno
FROM RANGE_TEST q
, (VALUES (20,29), (30,39), (40,49)) Range(L, U)
WHERE age BETWEEN L AND U
) r
WHERE rno = 1
ORDER BY age;
------------------------------------------------------------------------------

L U NAME AGE DEPARTMENT
----------- ----------- ------- ------ ----------
20 29 janet 22 HR
30 39 Nancy 33 Sales
40 49 John 45 IT

3 record(s) selected.
Back to top
Tonkuma
*nix forums Guru Wannabe


Joined: 07 Jun 2005
Posts: 178

PostPosted: Tue Feb 22, 2005 11:08 pm    Post subject: Re: how to extract one row from each range data Reply with quote

------------------------------ Commands Entered
------------------------------
SELECT L, U, name, age, department
FROM (SELECT q.*, L, U
, ROWNUMBER() OVER(PARTITION BY L ORDER BY age) rno
FROM RANGE_TEST q
, (VALUES (20,29), (30,39), (40,49)) Range(L, U)
WHERE age BETWEEN L AND U
) r
WHERE rno = 1
ORDER BY age;
------------------------------------------------------------------------------

L U NAME AGE DEPARTMENT
----------- ----------- ------- ------ ----------
20 29 janet 22 HR
30 39 Nancy 33 Sales
40 49 John 45 IT

3 record(s) selected.
Back to top
Tonkuma
*nix forums Guru Wannabe


Joined: 07 Jun 2005
Posts: 178

PostPosted: Tue Feb 22, 2005 10:26 pm    Post subject: Re: how to extract one row from each range data Reply with quote

------------------------------ Commands Entered
------------------------------
SELECT name, age, department
FROM (SELECT q.*
, ROWNUMBER() OVER(PARTITION BY age/10 ORDER BY age) rno
FROM RANGE_TEST q
) r
WHERE rno = 1
ORDER BY age;
------------------------------------------------------------------------------

NAME AGE DEPARTMENT
------- ------ ----------
janet 22 HR
Nancy 33 Sales
John 45 IT

3 record(s) selected.
Back to top
janet
*nix forums beginner


Joined: 22 Feb 2005
Posts: 2

PostPosted: Tue Feb 22, 2005 5:44 pm    Post subject: how to extract one row from each range data Reply with quote

hi

I want to extract one row from each range data.

For example , we had table had following data

name age department
janet 22 HR
John 45 IT
Jane 25 IT
Tom 35 HR
Nancy 33 Sales


I want to get any one row from age range 20~30, 30~40, 40~50

is there a single way to do that?
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 3:51 am | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Bug#379103: ITP: complearn-gui -- 3D drag-and-drop interf... Rudi Cilibrasi devel 0 Fri Jul 21, 2006 11:00 am
No new posts Bug#379087: ITP: libcomplearn -- data-compression based i... Rudi Cilibrasi devel 0 Fri Jul 21, 2006 7:40 am
No new posts FAQ 4.34 How do I extract selected columns from a string? PerlFAQ Server Perl 0 Fri Jul 21, 2006 7:03 am
No new posts Rejecting connections based on IP range. Evil Ernie Exim 2 Thu Jul 20, 2006 8:54 pm
No new posts How do I render JPEG Data stored in char* buffer? On the Sparrow C++ 2 Thu Jul 20, 2006 8:44 pm

Biker shirts shop | Free Ringtones | Loans | Problem Mortgage | Bankruptcy
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1637s ][ Queries: 20 (0.0876s) ][ GZIP on - Debug on ]