【发布时间】:2010-05-06 07:26:25
【问题描述】:
我有 3 个表要加入以获取 table1.code、table1.series、table2.entry_date、table3.title1 我正在尝试获取按 table1.code 和 table1.series 分组的最新非空 table3.title1。
select table1.code, table1.series, max(table2.entry_date), table3.Title1
from table3 INNER JOIN table2 ON table3.ID = table2.ID
INNER JOIN table1 ON table2.source_code = table1.code
where table3.Title1 is not NULL
group by table1.code, table1.series, table3.Title1
似乎给了我所有带有非空 title1 的条目而不是最近的条目。我应该如何构造查询以仅选择每个代码和系列的 Title1 的最新版本?
【问题讨论】:
-
您能提供一些示例数据吗?
标签: sql sql-server tsql