我的第一个表是 ProjectCustomFields
CustomFieldId ProjectId CustomFieldName CustomFieldRequired CustomFieldDataType
69 1 User Name 1 0
72 1 City 1 0
74 1 Email 0 0
82 1 Salary 1 2
我的第二个表是 ProjectCustomFieldValues
CustomFieldValueId ProjectId CustomFieldId CustomFieldValue RecordId
35 1 69 kaliya 1
36 1 72 Bangalore 1
37 1 74 mm@gmail.com 1
41 1 69 Yohesh 2
42 1 72 Delhi 2
43 1 74 2
50 1 69 sss 3
51 1 72 Delhi 3
52 1 74 sss@icsportal.in 3
57 1 69 Sunil 4
58 1 72 Mumbai 4
59 1 74 sunil@icsportal.in 4
60 1 82 20000 4
我试过下面的查询
Select M.CustomFieldName
, N.CustomFieldValue
, N.RecordId
From
(
Select G.CustomFieldName
, H.RecordId
From
(
Select CustomFieldName
From ProjectCustomFields
Where ProjectId = 1
) G
Cross Join
(
Select Distinct RecordId
From ProjectCustomFieldValues
) H
) M
Left Join
(
Select CustFiled.CustomFieldName
, CustValue.CustomFieldValue
, CustValue.RecordId
From ProjectCustomFieldValues CustValue
Left Join ProjectCustomFields CustFiled
On CustValue.CustomFieldId = CustFiled.CustomFieldId
Where CustValue.AuctionId = 1
) N
On M.CustomFieldName = N.CustomFieldName
And M.RecordId = N.RecordId
但我得到了下面的结果
#CustomFieldName# CustomFieldValue RecordId
User Name kaliya 1
City Bangalore 1
Email mm@gmail.com 1
Salary NULL **NULL**
User Name Yohesh 2
City Delhi 2
Email 2
Salary NULL **NULL**
User Name sss 3
City Delhi 3
Email sss@icsportal.in 3
Salary NULL **NULL**
User Name NULL **NULL**
City NULL **NULL**
Email NULL **NULL**
Salary NULL **NULL**
User Name Sunil 4
City Mumbai 4
Email sunil@icsportal.in 4
Salary 20000 4
但预期结果是
CustomFieldName CustomFieldValue RecordId
User Name kaliya 1
City Bangalore 1
Email mm@gmail.com 1
Salary NULL **1**
User Name Yohesh 2
City Delhi 2
Email 2
Salary NULL **2**
User Name sss 3
City Delhi 3
Email sss@icsportal.in 3
Salary NULL **3**
User Name Sunil 4
City Mumbai 4
Email sunil@icsportal.in 4
Salary 20000 4
请指导我一些,我尝试了很多但我在recordId中得到了空值,所以我需要相同的recordId高于一个..