问题描述
正确的人。
这里的第一次海报。
我有一张名为Trans的表,看起来像
批量,序列,客户,日期,交易
------------------- --------------------------------------
B100,1, C1,10 / 10/2007,T1
B100,2,C2,10 / 09/2007,T2
...
B78 ,5,C1,05 / 05/2007,T5
..
B69,3,C2,04 / 04/2007,T8
..
B53,3,C1,03 / 03/2007,T10
我需要的脚本必须经过所有在B100中记录并找到同一表中每个客户的最后一笔交易(按日期)。我基本上想结束
客户,日期
-------------------- -
C1,05 / 05/2007
C2,04 / 04/2007
希望有人能给我一个脚本来做。
谢谢
RebelDevil
Right folks.
First time poster here.
I have a table called Trans that looks like
Batch, Seq, Client, Date, Transaction
---------------------------------------------------------
B100, 1, C1, 10/09/2007, T1
B100, 2, C2, 10/09/2007, T2
...
B78, 5, C1, 05/05/2007, T5
..
B69, 3, C2, 04/04/2007, T8
..
B53, 3, C1, 03/03/2007, T10
The script I need will have to go through all recs in B100 and find the last transaction (by date) for each client within the same table. I basically want to end up with
Client, Date
----------------------
C1, 05/05/2007
C2, 04/04/2007
Hopefully somebody can give me a script to do it.
Thanks
RebelDevil
推荐答案
您的样本数据是不是很清楚,并没有与您的要求同步:
您希望每批下每个客户的最新交易。
样本数据
批量客户日期转换
B100 C1 10/09/2007 T1
B100 C1 05/05/2007 T2
B100 C2 10/09/2007 T3
B100 C2 05/04/2007 T4
然后您的样品输出应该看起来喜欢:
客户日期
C1 10/09/2007
C2 10/09/2007
...........
我认为我的理解是正确的,
尝试以下查询:
Your sample data is not that clear and is not with in sync of your requirement:
You want the latest transaction for each client under each batch.
Sample data
Batch client date trans
B100 C1 10/09/2007 T1
B100 C1 05/05/2007 T2
B100 C2 10/09/2007 T3
B100 C2 05/04/2007 T4
Then your sample output should look like:
Client Date
C1 10/09/2007
C2 10/09/2007
...........
I assume my understanding is correct,
try for below query:
尝试以下查询:
Try below query:
这篇关于加入相同的数据库表但只想找回一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!