MS Access从多行中选择字段

时间:2014-01-26 17:27:02

标签: ms-access select

我有一张表:

id|---|First|---|Second

1  ---  10   ---  100
2  ---  20   ---  200
3  ---  30   ---  300
4  ---  40   ---  400
5  ---  50   ---  500

我想创建一个返回的选择查询:

1 -- 10 -- 200
2 -- 20 -- 300
3 -- 30 -- 400
4 -- 40 -- 500

从id和First列获取(i)数据,从第二列获取(i + 1)数据。 我怎样才能做到这一点?

i -- i -- i+1

谢谢....

1 个答案:

答案 0 :(得分:1)

您可以使用此SQL语句:

SELECT TableName.ID, TableName.First, TableName_1.Second FROM TableName AS TableName_1 INNER JOIN TableName ON TableName_1.ID = TableName.ID+1;

其中TableName是您的表名。

或使用WHERE子句:

SELECT TableName.ID, TableName.First, TableName_1.Second FROM TableName, TableName AS TableName_1 WHERE TableName_1.ID = TableName.ID+1