2011-04-10 25 views
0

我們希望有一個輸出表,以獲得行模擬產出表獲得

DB行:

SampleTable1

Name  Product

Jan   Book 
Smith  Glass 
....  ..... 


select * from SampleTable1 

我想造成這種選擇相同的以下輸出。

輸出:

Row  Name  Product

1   Jan   Book   
    2   Smith  Glass 
    3   ....  ..... 

在Access 2007

+1

您所標記的MySQL,ORCLE和SQL服務器2008年。您需要哪種解決方案? – 2011-04-10 18:44:03

回答

2

對於Oracle,你可以做

select rownum as Row, Name, Product 
    from SampleTable1; 

對於MySQL:

select @rownum := @rownum + 1 as Row, Name, Product 
    from SampleTable1, (select @rownum := 0) 

對於SQL Server:

select row_number() over (order by Name) as Row, Name, Product 
    from SampleTable1 
+0

不錯,爲所有3回答。 – Hogan 2011-04-10 18:56:08

0
SELECT Name, Product, row_number() OVER (ORDER BY Name) AS Row 
    FROM SampleTable1 
0

在MySQL我認爲這將是這樣的:

select @rownum:[email protected]+1 slno, s.* from SampleTable1 s, (SELECT @rownum:=0) r