2
Answers

Row Numbers. using Sql Query

Ramco Ramco

Ramco Ramco

2w
126
1

Hi

 I have below data and i want to display Row Numbers. using Sql Query

Row Number G/l Account Debit Credit
1 3001 0 0
2 3001 0 0
3 3001 0 0
4 3001 0 0
5 3001 0 0
6 3001 0 0
7 3001 650.16 0
8 3001 31,860.00 0
9 3001 0 100
1 3002 100 0
2 3002 200.00 0
3 3002 0 50

Thanks

Answers (2)
0
Muhammad Imran Ansari

Muhammad Imran Ansari

261 7.4k 324.5k 2w

Hello Ramco,

To display Row Numbers that reset for each G/L Account, use the ROW_NUMBER() function with PARTITION BY.

SELECT 
    ROW_NUMBER() OVER (PARTITION BY [G/l Account] ORDER BY [G/l Account]) AS [Row Number], 
    [G/l Account], 
    Debit, 
    Credit
FROM Masters;

Good Luck!

0
Emily Foster

Emily Foster

876 865 0 2w

Hi! To display row numbers in SQL, you can use the ROW_NUMBER() function. This function assigns a unique sequential integer to each row within a partition of a result set.

Here is an example SQL query that demonstrates how to display row numbers based on your provided data:


SELECT
    ROW_NUMBER() OVER (ORDER BY [G/l Account]) AS RowNumber,
    [G/l Account],
    Debit,
    Credit
FROM
    YourTableName

Replace `YourTableName` with the actual name of your table where this data is stored. By using the `ROW_NUMBER() OVER (ORDER BY [G/l Account])` clause, you assign row numbers based on the order of the G/l Account.

This query will generate row numbers for each row in the result set, allowing you to uniquely identify each row. Let me know if you need further assistance or have any other questions!