473,509 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Number grouped rows....please help!!

4 New Member
Hi,

If i have the following table ( this is an example...)

Class Type
A A112
A A2
A A108
A A218
A A328
B B58
B B2
B B54
B B110
B B166
C C14
C C2
C C10

How do I number the rows so that each distinct row is numbered but within the class so that they expected output is:

Class Type output
A A112 1
A A2 2
A A108 3
A A218 4
A A328 5
B B58 1
B B2 2
B B54 3
B B110 4
B B166 5
C C14 1
C C2 2
C C10 3

Please please please help me!! I can't think on how to do this!

Thanks!!
Dec 10 '07 #1
3 1268
nedu
65 New Member
Try using this if u r using SQL Server 2000 or lower versions . . .

CREATE TABLE #RowNumber ( RowNumber int IDENTITY (1, 1), Class char(9), Type1 char(10) )

INSERT #RowNumber (Class ,Type1)
SELECT Class ,Type1
FROM tablename group by Class ,Type1

Select * from #RowNumber


Thanks,
Nedu. M
Dec 11 '07 #2
Jim Doherty
897 Recognized Expert Contributor
Hi,

If i have the following table ( this is an example...)

Class Type
A A112
A A2
A A108
A A218
A A328
B B58
B B2
B B54
B B110
B B166
C C14
C C2
C C10

How do I number the rows so that each distinct row is numbered but within the class so that they expected output is:

Class Type output
A A112 1
A A2 2
A A108 3
A A218 4
A A328 5
B B58 1
B B2 2
B B54 3
B B110 4
B B166 5
C C14 1
C C2 2
C C10 3

Please please please help me!! I can't think on how to do this!

Thanks!!
Assuming your table is called tblClass try this

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT Class, Type,
  2.                          (SELECT DISTINCT COUNT(*)
  3.                             FROM         tblclass e2
  4.                             WHERE     e2.class = e.class AND e2.type <= e.type) AS [Output]
  5. FROM dbo.tblClass e
Regards

Jim :)
Dec 11 '07 #3
arghhh
4 New Member
Thank you so much Jim!

You've saved my query :-)
Dec 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4066
by: anthonyberet | last post by:
I work for an organisation that uses a bespoke document imaging system, the database of which is an MS sql server. We have MS Access and already use it for some querying of the database. The...
10
1811
by: Nevets Steprock | last post by:
I'm writing a web program where one of the sections is supposed to output a correlation matrix. The typical correlation matrix looks like this: ..23 ..34 .54 ..76 .44 .28 ..02 .77 ...
7
42637
by: deep022in | last post by:
guys, I have written a perl script using Win32::OLe module. I was able to read it completly. but I have to specify the number of rows in excel sheet as command line option. I want to know how...
0
6171
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on...
14
1877
by: ankitmathur | last post by:
Hi, I'm facing a pretty peculiar problem. In one of my pages I print the number of rows depending upon the number of Qty I got filled in my previous page i.e. If Qty is filled in as 3 in...
6
3282
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
1
1332
by: Rainer Queck | last post by:
Hello NG, I am using a typed DataSet, created with VS dataset designer. I have the problem , that a table in the dataset refuses to read a xml file. The strange thing is that if I create a...
0
1401
by: Alex | last post by:
Hi, I am a complete beginner with Oracle 9i and XML within it, not XML alone though. I am trying to do a regular SELECT statement using the SQL Scratchpad within the Oracle Enterprise Manager and...
4
6884
by: questionit | last post by:
How do i retreive 10 rows from a table using SQL SELECT Names from Customers... how do i change it to retrieve only 'n' number of rows? Please suggest an easy method Thanks
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.