我正在尝试从table1执行techID的外连接以从表2中提取日期。问题是techID在每个表中多次重复。我希望日期按顺序列出,但一旦没有更多数据就停止匹配。例如
techID |Order#
tech1 order1
tech2 order2
tech3 order3
tech4 order4
tech3 order5
tech3 order6
techID |Month
tech3 Oct-01
tech3 Nov-02
tech2 Jan-10
tech1 Jan-11
tech1 Feb-02
tech4 Feb-04
output
tech1 Feb-02
tech2 Jan-10
tech3 Oct-01
tech4 Feb-04
tech3 Nov-02
tech3
现在我所拥有的只是一个子查询,但它与我的需求无关......帮助!
(select last(table2.[shipping_date])
from table2
where table1.techid = table2.techid ) AS shippedon
答案 0 :(得分:0)
您需要的是INNER JOIN,其中月份字段为MAX,TECID为GROUP BY。像
这样的东西SELECT
techTableName.techID,
Max(projectTableName.monthFieldName) As MaxOfMonth
FROM
techTableName
INNER JOIN
projectTableName
ON
techTableName.techID = projectTableName.techID
GROUP BY
techTableName.techID;
但是,我没有看到 JOIN 中的任何一点,这个假设基于您提供的数据集,查询可能很简单。
SELECT
projectTableName.techID,
Max(projectTableName.monthFieldName) As MaxOfMonth
FROM
projectTableName
GROUP BY
projectTableName.techID