ADDING A count +1

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

ADDING A count +1

Post by sal21 »

I have sql="select aaa from table"
this return

AAA
BBB
CCC
DDD

I need

AAA 1
BBB 2
CCC 3
DDD 4
... .

User avatar
HansV
Administrator
Posts: 78463
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ADDING A count +1

Post by HansV »

If the values of the aaa field are unique, you can use

sql = "SELECT aaa, (SELECT Count(*) FROM Table AS T WHERE T.aaa <= Table.aaa) AS Seq FROM Table"
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: ADDING A count +1

Post by burrina »

What happens when you get to Z ?

User avatar
HansV
Administrator
Posts: 78463
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ADDING A count +1

Post by HansV »

I don't think Sal meant those values literally.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: ADDING A count +1

Post by sal21 »

HansV wrote:
14 Mar 2021, 22:02
If the values of the aaa field are unique, you can use

sql = "SELECT aaa, (SELECT Count(*) FROM Table AS T WHERE T.aaa <= Table.aaa) AS Seq FROM Table"
:clapping: