与“最后"的内部加入 [英] Inner join with "Last"

查看:65
本文介绍了与“最后"的内部加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个带有两个/三个对应代码的帐号列表.但是,我只需要最新的代码,而忽略先前的代码,如果我使用普通的联接查询,它将包括所有相应的代码,我该如何进行查询,使其仅使用最新的代码?感谢您有任何建议,任何人都可以提供.

我尝试使用last(),但是它不起作用.

Hi, I have a list of account numbers with two/three corresponding codes. However I only need the most recent code and ignore the previous codes, if I were to use a normal join query it will include all the corresponding codes, how do I do the query so it only takes only the most recent code? Thanks for any advice anyone might be able to offer on this.

I tried using a last() but it doesnt work.

SELECT DISTINCT taa.AS400, taa.Company, taa.Account_Area, taa.Customer_Account, LAST(OMDIM1) as test

FROM dbo.testAccountArea taa

LEFT JOIN dbo.vtbl_orbt_fmosal_vantage sal

ON

taa.AS400 = sal.OMAS400 AND taa.Company = sal.OMCOMP AND taa.Customer_Account = sal.OMCUST

推荐答案

首先,语句select distinct ..., last(...)有点奇怪,因为最后只能有一个记录,所以distinct没有用.我也不知道OMDIM1的来源,但是我会尝试这样的方法:

First of all, the statement select distinct ..., last(...) is somewhat strange because there can only be one last record so distinct has no use. I also don''t know where OMDIM1 is coming from, but I would try something like this:

select distinct t1.a, t1.b, t1.c from t1 where t1.a = (select last(t2.a) from t2)



它不是最漂亮的sql语法,但希望此示例能够实现.

祝你好运!



It''s not the most beautiful sql syntax but for the sake of this example will hopefully do.

Good luck!


这篇关于与“最后"的内部加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆