如何将选择结果列附加到mysql中的anther select结果中

时间:2015-11-17 18:40:25

标签: mysql sql

以下是样本选择1:

    aStarResult=aStarSearch(tileAStarSearch, frontier);
  File "C:\Users\zjalmahmoud\workspace\Tile_Problem\search.py", line 211, in aStarSearch
    frontier.push(c) #add it to the queue
  File "C:\Users\zjalmahmoud\workspace\Tile_Problem\utilsSimple.py", line 61, in push
    insort(self.q, (self.f(item), item))
TypeError: unorderable types: Node() < Node()

这是第二个:

SELECT A, B FROM Table1

选择1和选择2的记录数量是相同的,结果应该是:

SELECT C, D FROM Table2

好的,我提供了一些数据结果:

结果1:

A, B, C, D

结果2:

+---+---+
| A | B |
+---+---+
| 1 | 2 |
| 3 | 4 |
| 5 | 6 |
+---+---+

最终结果应该是:

+---+----+
| C | D  |
+---+----+
| 4 |  8 |
| 5 |  9 |
| 6 | 10 |
+---+----+

1 个答案:

答案 0 :(得分:3)

创意:使用您可以加入的唯一密钥,例如:行号/等级。这是一个有效的例子:(SQLFiddle

set @rank1 := 0;
set @rank2 := 0;
select a, b, c, d
from
  (select @rank1 := @rank1 + 1 AS rank, a, b from table1) t1 inner join
  (select @rank2 := @rank2 + 1 AS rank, c, d from table2) t2 on t2.rank = t1.rank
order by t1.rank