Board index » delphi » how to change some records with another records at the same table

how to change some records with another records at the same table

hi,every
I have a table below:

in_no           zyh                                   paidcount
200205240030 P0024000075                              8
200205240030 P0030000104                              5
200205240030 P0032000005                              4
200205240030 P0034000010                              3
200205240030 P0124000053                              2
200205240031 P0023000073                              1
200205240031 P0024000075                              1
200205240031 P0030000104                              1
200205240031 P0032000005                              1
200205240031 P0034000010                              1
200205240031 P0124000053                              1

 update  a set paidcount=a.paidcount-b.paidcount   from (select * from
indetail where in_no='200205240030') as a,(select * from indetail where
in_no='200205240031') as b
         where a.zyh=b.zyh
the query dont work, maybe some one can tell me how to achieve the correct
result.

thanks in advance.

 

Re:how to change some records with another records at the same table


I'm not certain it will work, but you might try something like this:

Update indetail
Set PaidCount = (Select (a.PaidCount - b.PaidCount)
                           from indetail a,
                                   indetail b
                           where a.in_no='200205240030'
                              and  b.in_no='200205240031'
                              and  a.zyh = b.zyh)

Re:how to change some records with another records at the same table


hi,every
I have a table below:

in_no           zyh                                   paidcount
200205240030 P0024000075                              8
200205240030 P0030000104                              5
200205240030 P0032000005                              4
200205240030 P0034000010                              3
200205240030 P0124000053                              2
200205240031 P0023000073                              1
200205240031 P0024000075                              1
200205240031 P0030000104                              1
200205240031 P0032000005                              1
200205240031 P0034000010                              1
200205240031 P0124000053                              1

 update  a set paidcount=a.paidcount-b.paidcount   from (select * from
indetail where in_no='200205240030') as a,(select * from indetail where
in_no='200205240031') as b
         where a.zyh=b.zyh
the query dont work, maybe some one can tell me how to achieve the correct
result.

thanks in advance.

Other Threads