我有两张桌子;Items我Items_history正在尝试加入。
- 第一个表 (
Items):有一个带有当前日期的 item 键实例 - 第二个表 (
Items_history):具有多个日期的同一项目键的多个实例。只希望第一个表中的项目键具有第二个表的最小日期
Items Table: Items_History table: Results:
item_key date item_key date item_key date
1 1/1/2019 1 1/1/2019 1 8/30/2018
2 12/30/2018 1 10/30/2018 2 10/15/2018
1 08/30/2018
2 12/30/2018
2 10/15/2018
到目前为止我所拥有的:
select c.item_key,min(a.CREATE_TMSTMP)
from wf_items_history a
inner join wf_items c on c.item_key = a.item_key and c.form_number = 'MV1' and c.ASSIGNED_WORKGROUP = 'NONV'
group by c. item_key, a.create_tmstmp