我有两个表,需要创建一个查询,用最新的日记更新带回所有当前打开的查询
表 - sv_inquiry
inquiry_id | status | state | owner_grp |
------------------------------------------------
1 OPEN Acknowledged DEV
2 OPEN Acknowledged DEV
3 OPEN Reassigned DEV
4 OPEN Reassigned DEV
表 - sv_diary
diary_id| inquiry_id | change_dt| change_uid |
------------------------------------------------
1 1 2/1/2013 JBLOGGS
2 1 3/1/2013 JBLOGGS
3 1 4/1/2013 JSMITH
1 2 2/1/2013 JBLOGGS
2 2 4/1/2013 JSMITH
1 3 4/1/2013 JSMITH
2 3 6/1/2013 JBLOGGS
1 4 5/1/2013 JBLOGGS
2 4 8/1/2013 JBLOGGS
我现在使用的代码是
SELECT
t1.inquiry_id,
t1.state,
t1.status,
t1.business_impact,
t1.priority,
t1.owner_rep,
t1.owner_grp,
t2.change_dt as diary_updated,
t2.change_uid as diary_updated_by
FROM sv_inquiry t1
JOIN sv_diary t2
on t1.inquiry_id = t2.inquiry_id
WHERE
owner_grp = 'DEV'
AND state <> 'Closed'
AND status is not null
但是,当我只想要基于 sv_diary 表中日期的最新条目时,这会带回每个查询的所有日记条目。我该怎么做呢?
为表格的垃圾格式道歉,但我不知道如何在这个网站上创建一个像样的表格结构。
谢谢