SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 07-02-2008, 03:50 PM
Jeremias Spoken Jeremias Spoken is offline
Junior Member
 
Join Date: Jun 2008
Posts: 5
Jeremias Spoken is on a distinguished road
Default ANY dialect question:

Row Number Each Group


Hi...!

To a similar table I need to add a row number...

Code:
GRP          RowNR
73463          1
73463          2
73463          3
73463          4
53246          1
53246          2
78843          1
43543          1
43543          2
43543          3
43543          4
43543          5
Please don't tell me that use Temp Tables, if it's possible only T-SQL... I use DB2 over ISeries...

With ROW_NUMBER() OVER() is like a sequence but doesn't work for each group...

Thanks in advance and regards...!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 07-02-2008, 05:04 PM
Jeremias Spoken Jeremias Spoken is offline
Junior Member
 
Join Date: Jun 2008
Posts: 5
Jeremias Spoken is on a distinguished road
Default ANY answer. Re: Row Number Each Group

Hi hail...!

Here the solution (DB2):

SELECT C.CTA, ROW#
FROM TABLENAME C,
TABLE <b>(SELECT COUNT(*) AS ROW#
FROM TABLENAME C2
WHERE C2.CTA = C.CTA AND C2.CTA1 <= C.CTA1)</b> AS TABLENAME_ORDER
ORDER BY C.CTA, ROW#;
In this T-SQL CTA1 is another field different that CTA.

Follow next link for 2 ways in SQLServer:
tek-tips forums

Best regards...!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:34 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8