Home > database >  The problem is how to do ah?
The problem is how to do ah?

Time:09-21

Don't know how to do it, need to turn the

CodePudding user response:

Select p.i d_p, p.n ame, p.a ddress,. V1, v2. The value ID, value phone v3. Value Department
From person, p value v1, value v2, value the v3
Where p.i d_p=v1. Id_p (+)
And v1. Type (+)='Phone'
And p.i d_p=v2. Id_p (+)
And v2. Type (+)='ID'
And p.i d_p=v3. Id_p (+)
And the v3. Type (+)='Department'
And the exists (
Select * from value v4 where v4. Id_p=p.i d_p
)



The select p.i d_p, p.n ame, p.a ddress,
(select a value from the value v1 where v1. Id_p=p.i d_p and v1. Type='Phone') Phone,
(select a value from the value v1 where v1. Id_p=p.i d_p and v1. Type='ID') ID,
(select a value from the value v1 where v1. Id_p=p.i d_p and v1. Type='Department') Department
From the person p
Where the exists (
Select * from value v4 where v4. Id_p=p.i d_p
)

CodePudding user response:

The select p.I D_P
Max (p.N ame) as the Name
Max (p.A ddress) as the Address
, Max (case when v.T ype='Phone' then v.V alue else 'end) as Phone
, Max (case when v.T ype='ID' then v.V alue else 'end) as ID
, Max (case when v.T ype='Department' then v.V alue else 'end) as Department
From the person p left join the value v on p.I D_P=v.I D_P
Group by p.I D_P
  • Related