If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > update recnos within groups

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-26-03, 05:54
rdb#user rdb#user is offline
Registered User
 
Join Date: Jun 2003
Posts: 2
update recnos within groups

i need to update a table with ascending recnos within a group (with sorted names)

does anyone know how to solve it in ansi sql ?

id grp name rec
-- --- ----- ---
1 a joe (1)
2 a john (2)
3 b james (1)
4 b jill (2)
5 b jim (3)
6 c jack (1)
7 d jesse (1)

update tab
set rec = ...
Reply With Quote
  #2 (permalink)  
Old 06-26-03, 11:36
dbmadcap dbmadcap is offline
Registered User
 
Join Date: May 2003
Posts: 87
Ansi SQL ? Which database ? I cant recollect any way to do it but if you can tell us the database you are using, may be using the database feature the query might be possible.
Reply With Quote
  #3 (permalink)  
Old 06-30-03, 05:11
rdb#user rdb#user is offline
Registered User
 
Join Date: Jun 2003
Posts: 2
after some hours of trying i found this sql query with select


select a.grp, a.name, count(*) "rec"
from tab a, tab b
where b.grp = a.grp
and b.name <= a.name
group by a.grp, a.name;


with this result:


id grp name rec
-- --- ----- ---
1 a joe 1
2 a john 2
3 b james 1
4 b jill 2
5 b jim 3
6 c jack 1
7 d jesse 1


but how does an update work ?


PS: i'm using sas, a statistical software, in which i can use 'naked' sql
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On