0
with one as
(Select sno = ROW_NUMBER()OVER (order by complaint_id), Complaint_Id, Complaint.ComplaintType_id, Complaint.complaintProfileId, Complaint.Description,
Complaint.Email, Complaint.PriorityLevel_id, Complaint.Date_Complained, Complaint.Status, Complaint.AdminComments, Complaint.Phone, Complaint.Evidence
from Complaints Complaint)
此查詢的結果是(不是整個結果)內連接兩個表,與第
sno complaintProfileId
1 14
2 15
3 15
4 14
5 14
6 13
第二子查詢:
two as
(SELECT Complaint.complaintProfileId,
CASE
WHEN MMB_Name IS NOT NULL THEN MMB_Name
WHEN UPPMembership.profile_id IS NOT NULL THEN 'UPP'
ELSE 'Not found'
END as Name
FROM Complaints Complaint
LEFT JOIN MMBMembership
ON MMBMembership.profile_id = Complaint.complaintProfileId
left JOIN MMB_BusinessProfiles mmbProfiles
ON mmbProfiles.MMB_id = MMBMembership.MMB_id
LEFT JOIN UPPMembership
ON UPPMembership.profile_id = Complaint.complaintProfileId)
complaintProfileId Name
14 UPP
15 Marlon
15 Marlon
14 UPP
14 UPP
13 Rodolfo
所以這是我在哪裏遇到問題
select one.*, two.Name
from one join two
on one.complaintProfileId = two.complaintProfileId
This query returns 36 records.
id 14返回9times和15-6times等..
我做一個內部聯接,但仍不能確定
感謝 孫
好的,謝謝你,我用SNo加入 – Sun
你可能*已經在'two'裏擺脫了Complaint的連接。 –