Home > database >  According to conditions of left join the corresponding table
According to conditions of left join the corresponding table

Time:09-17

Using the oracle, left table contains a accounting subject acct_cd, if a accounting subject is' 1001 ', then the connection b table for balance amt, namely
Select * from a
Left the join b
Using (cust_no)
When a accounts for '1002', the connection table c get balance, namely
Select * from a
Left the join c
Using (cust_no)

Now have a solution:
A select few fields, case acct_cd when '1001' then b.a mt, when '1002' then c.a. mt
From a
Left the join b
Using (cust_no)
Left the join c
Using (cust_no)

Scheme 2:
A select few fields, amt
From a
Left the join b
Using (cust_no)
Where a.a cct_cd='1001'
Union all
A select few fields, amt
From a
Left the join c
Using (cust_no)
Where a.a cct_cd='1002'

Excuse me which solution is better, in the actual cases, the subject is more, if use 2 code would seem to be very long, but plan a is likely to lower efficiency? There is no better solution? Thank you for your bosses

CodePudding user response:

Solution in the presence of a pair of long may the bug, who quickly slow depends, if you want to clear logic, not directly make the pretreatment on the balance sheet

CodePudding user response:

reference 1st floor nayi_224 response:
solution in the presence of a double time may be a bug, who quickly slow depends, if you want to clear logic, directly on the balance sheet is better than do the pretreatment
what bug?
  • Related