× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Good morning, folks,

I am trying to find out how to do the following without having to jump through coding loops to get there.
I need to come up with an SQL statement that generates a sequence number (1, 2, 3, etc) (aka "row number") within a group of records having the same (composite) key value, with separate numbering within each key value group.

For example, from the following:


K1 K2 data

1 ABC ...
1 DEF ...
1 GHI ...
2 any ...
2 more ...
3 justone
4 xyz


Output would look like this, generated row numbers within groups of K1 values:

K1 K2 data row#

1 ABC ... 1
1 DEF ... 2
1 GHI ... 3

2 any ... 1
2 more ... 2

4 xyz ... 1

I've looked at the IBM I documentation and done a search and the closest I came up to what I need is here:
http://archive.midrange.com/midrange-l/201505/msg00438.html

And I found the SQL reference for this row-number() clause, but it has nothing about row numbers within a group value (or "group partition")

select row_number() over (order by colb asc) as number,
cola, colb, colc
from qtemp.mytable
where cola is not null
order by colb
NUMBER COLA COLB COLC
1 B 2 3
2 A 65 1
3 D 72 2
4 C 101 4



Alan Cassidy
Softare Engineer
Direct Phone - 954-693-0000 Ext. 3433
ACassidy@xxxxxxxxxxxxxx<mailto:ACassidy@xxxxxxxxxxxxxx>
www.hppartners.com<http://www.hppartners.com/>

[HPP Logo FINAL with name-tag-logo-TM]



--------------------------------------------------------------------------------
Confidentiality Notice: This email may contain confidential information or information covered under the Privacy Act, 5 USC 552(a), and/or the Health Insurance Portability and Accountability Act (PL 104-191) and its various implementing regulations and must be protected in accordance with those provisions. It contains information that is legally privileged, confidential or otherwise protected from use or disclosure. This e-mail message, including any attachments, is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. You, the recipient, are obligated to maintain it in a safe, secure and confidential manner. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Thank you.
--------------------------------------------------------------------------------

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.