我有两个表:
T_STOCK
: primary key is id
, seller
, and some others fields let say a
and b
.
T_FLOW
: primary key is (id
+ startdate
), and some others fields, for example c
and d
.
我想问一下的是,每个记录的所有栏目均从<代码>T_STOCK退回到具体seller
,但用栏目填写(
startDate
,c
和d
) 页: 1
The relation between T_STOCK
and T_FLOW
is based on the id
attribute.
Everytime a record with a specific ID exists in T_STOCK
, at least one record exist in T_FLOW
for this ID.
然而,在<代码>上可能存在不止一个记录。 T_FLOW。 在这种情况下,我必须只考虑,最近一次是(即max(startDate)
)。
换言之,如果我们有以下表格内容:
+---------------------+
| T_STOCK |
+----+--------+---+---+
| ID | SELLER | a | b |
+----+--------+---+---+
| 01 | foobar | 1 | 2 |
+----+--------+---+---+
| 02 | foobar | 3 | 4 |
+----+--------+---+---+
| 03 | foobar | 5 | 6 |
+----+--------+---+---+
+---------------------------+
| T_FLOW |
+----+------------+----+----+
| ID | StartDate | c | d |
+----+------------+----+----+
| 01 | 01/01/2010 | 7 | 8 |
+----+------------+----+----+
| 02 | 01/01/2010 | 9 | 10 |
+----+------------+----+----+
| 02 | 07/01/2010 | 11 | 12 |
+----+------------+----+----+
| 03 | 03/01/2010 | 13 | 14 |
+----+------------+----+----+
| 03 | 05/01/2010 | 15 | 16 |
+----+------------+----+----+
质询的结果必须是:
+----+--------+---+---+------------+----+----+
| ID | SELLER | a | b | startDate | c | d |
+----+--------+---+---+------------+----+----+
| 01 | foobar | 1 | 2 | 01/01/2010 | 7 | 8 |
+----+--------+---+---+------------+----+----+
| 02 | foobar | 3 | 4 | 03/01/2010 | 11 | 12 |
+----+--------+---+---+------------+----+----+
| 03 | foobar | 5 | 6 | 01/01/2010 | 15 | 16 |
+----+--------+---+---+------------+----+----+
当时我如何写我的问话?