2

datetime2 つのテーブルを列で結合する際に問題があります。

のようなものに参加する必要がありTable1.datetime>MAX(Table2.datetime)ます。他に参加できるコラムはありません。手伝って頂けますか?

Table1(370.000 行以上):

timestamp                data1  data2  data3
-----------------------  -----  -----  -----
2011-05-09 08:55:19.990  x1     w12    j3
2011-05-09 08:56:19.990  x4     w22    j3
2011-05-09 08:57:19.990  x5     w23    j3
2011-05-09 08:58:19.990  x7     w25    j3
2011-05-09 08:59:19.990  x2     w19    j3
2011-05-09 09:01:19.990  x3     w18    j3

Table2(2.000 行以上):

timestamp                data8
-----------------------  -----
2011-05-09 07:55:11.990  y1
2011-05-09 07:56:13.990  y9
2011-05-09 08:17:14.990  y3
2011-05-09 08:28:15.990  y8
2011-05-09 08:59:16.990  y5
2011-05-09 09:02:19.990  y6

したがって、Table1結合されたデータには次のTable2値が必要です。

timestamp                data1  data2  data3  timestamp                data8
-----------------------  -----  -----  -----  -----------------------  -----
2011-05-09 08:55:19.990  x1     w12    j3     2011-05-09 08:28:15.990  y8
2011-05-09 08:56:19.990  x4     w22    j3     2011-05-09 08:28:15.990  y8
2011-05-09 08:57:19.990  x5     w23    j3     2011-05-09 08:28:15.990  y8
2011-05-09 08:58:19.990  x7     w25    j3     2011-05-09 08:28:15.990  y8
2011-05-09 08:59:19.990  x2     w19    j3     2011-05-09 08:59:16.990  y5
2011-05-09 09:01:19.990  x3     w18    j3     2011-05-09 08:59:16.990  y5
4

2 に答える 2

0

If I understood your question correctly, you need to join the whole Table2 to every row of Table 1, where Table1.timestamp > Max(Table2.timestamp)? Well, the below query should do the trick, but may be you need to clarify the question.

Select * from Table1 t1, Table2 t2
Where t1.timestamp > (select MAX(t3.timestamp) from Table2 t3)
于 2013-07-11T13:26:05.777 に答える