Home > database >  On field, many results back. Ball bosses to solve!
On field, many results back. Ball bosses to solve!

Time:12-23

For example, I now have two table
Personnel information table
The name | home | homeNow
Zhang SAN | | 02 01
Li si | | 02 02

Area table
Id | name
01
| Beijing02 | Shanghai
03 | guangdong

Home=home address
HomeNow=current address

So now I want to query each person's information, this is
Select the personnel information table. The name name area table. name home address , area table. name current address the from personnel information table, table in the where don't know how to write


The judge how to write? A field, can be used in two places, dizzy, beg god grant instruction!

CodePudding user response:

The select a.n ame name
, b.n ame home address
, citigroup ame current address
The from personnel information form a
Left in the join table b on a.h ome=b.i d
Left in the join table c on a.h omenow=c.i d

CodePudding user response:

Select the name
, decode (home, '01', 'Beijing', '02', 'Shanghai', '3', 'guangdong')
, decode (homeNow, '01', 'Beijing', '02', 'Shanghai', '3', 'guangdong')
The from personnel information table
Written judgment: decode can also switch to case the when
  • Related