Link to home
Start Free TrialLog in
Avatar of Tpaul_10
Tpaul_10Flag for United States of America

asked on

Select Statement

Experts,

Here is the SQL I am running and no problems with the SQL.

select       T1.Column1,T2.Column3,count(T1.Column6) as TestColumn1
from       Table T1
inner join Tablle2 T2
on T1.Column1 = T2.Column1
where       T1.Column1 > 'myvalue'
group by  T1.Column1,T2.Column3

union
select       T1.Column1,T3.Column3,count(T1.Column6) as TestColumn1
from       Table T1
inner join TempTablle T3
on T1.Column1 = T3.Column1
where       T3.Column3 > 'myvalue'
group by  T1.Column1,T3.Column3


I need to add one more column to my select and the output or the result of the newcolumn is like following.

C1 C2  C3   NewColumn
A   100     1          1
B    200     0          2
C   500     1           3
D   720     1           4


if my select gives 2 rows, newcolumns values should be 1 and 2
if my select gives 10 rows, newcolumns values should be 1 to 10

Thanks in advance and let me know if the question is not clear.
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>then add the ROW_NUMBER counter over it.<<
Let's hope, they are at least using SQL Server 2005 (if not 2008).
select Columns 1...4, Rownumber()(order by columns1)
from (your query)