English 中文(简体)
如何将三个领域与两个表相匹配,以便在对应时更新相同的表格。
原标题:How do i go about matching three fields from two tables in order to update the same tables in case of match

表2 在MySQL数据库中的A和B,如果并且只有在表A所述行的某些领域与表B不同行的田地完全吻合的情况下,如何更新表A的行文。 表B中的行数必须每次使用一次,每次使用一次。 因此,表B中的一行在表A中设有连接一行的田间,不能利用收益与表A中的任何其他行相匹配。

我曾尝试过

UPDATE
    Table A,
    表B
SET 
    Table A.Status =  MATCHED ,
        表B.Status =  USED 
WHERE
    表B.Status IS NULL
AND 
    Table A.Field1 = 表B.Field1
AND 
    Table A.Field2 = 表B.Field2

不幸的是,这并没有给我带来预期的结果,因为表A的不同行文往往与表B中的相同行文吻合。

例如: 表A

ID  Date       Ref    Amount  Status 
1   2009-10-20 773    300000         
2   2009-10-20 773    10000   MATCHED
3   2009-10-20 773    150000         
4   2009-10-20 773    20000   MATCHED
5   2009-10-20 773    140000  MATCHED

表B

 Ref Amount Date       ID
 870 50000  2009-11-01 1 
 871 50000  2009-11-01 2 
 871 80000  2009-11-01 3 
 871 20000  2009-11-01 4 
 871 20000  2009-11-01 5 
 871 20000  2009-11-01 6 
 872 300000 2009-11-01 7 

采用参考、数额和日期。

最佳回答

避免重新使用,是否简单地将《惠于公约》条款中的排除包括在内?

AND Table A.Status <>  MATCHED 
AND Table B.Status <>  USED 

如果各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行,但若行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行将行各行各行各行。 我很抱歉不要对此进行测试;我在这里没有我的我的我的我的我的我的我的我的智慧,来尝试这样做。

问题回答

• 在表格A和表格B的记录之间增加1:1比比的“WHERE”条款的条件?





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签