本文介绍了此查询不适用于所有ID ..(即使它们不为null)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了不同的属性ID,但它不适用于某些ID。我不知道这段代码有什么问题?
我尝试过的方法:
I tried it for different Property Ids, but it is not working for some Ids. I don't know what is wrong with this code?
What I have tried:
select distinct Property.Id,Property.Name,
Person.FirstName,Person.MiddleName,Person.LastName,
ad.Number,ad.Suburb,ad.Street,ad.City,ad.Region,ad.PostCode,Property.Bedroom,Property.Bathroom,
PropertyRentalPayment.Amount AS Rental_Payment,TenantPaymentFrequencies.Code AS Rental_Frequency
from Property,Address ad,PropertyRentalPayment,TenantPaymentFrequencies,OwnerProperty,Person,TenantProperty
where Property.AddressId=ad.AddressId
AND Property.Id=PropertyRentalPayment.PropertyId
AND TenantPaymentFrequencies.Id=PropertyRentalPayment.FrequencyType
AND TenantProperty.PropertyId=Property.Id
AND Person.Id=OwnerProperty.OwnerId
AND Property.Id=OwnerProperty.PropertyId
AND TenantProperty.PaymentFrequencyId=TenantPaymentFrequencies.Id
AND Property.Id=@PropertyId;
推荐答案
SELECT DISTINCT PRO.Id, PRO.Name, PER.FirstName, PER.MiddleName, PER.LastName,
AD.Number, AD.Suburb, AD.Street, AD.City, AD.Region, AD.PostCode, PRO.Bedroom, PRO.Bathroom,
PRP.Amount AS Rental_Payment,TPF.Code AS Rental_Frequency
FROM Property AS PRO
INNER JOIN Address AS AD ON PRO.AddressId=AD.AddressId
INNER JOIN PropertyRentalPayment AS PRP ON PRO.Id=PRP.PropertyId
INNER JOIN TenantProperty TPR ON TPR.PropertyId=PRO.Id
INNER JOIN TenantPaymentFrequencies AS TPF ON TPF.Id=PRP.FrequencyType AND TPR.PaymentFrequencyId=TPF.Id
INNER JOIN OwnerProperty AS OWP ON PRO.Id=OWP.OwnerId
INNER JOIN Person AS PER ON [!Missed_Relationship!]
WHERE PRO.Id=@PropertyId;
如需了解更多详情,请看到这篇优秀文章: []
祝你好运!
For further details, please see this excellent article: Visual Representation of SQL Joins[^]
Good luck!
这篇关于此查询不适用于所有ID ..(即使它们不为null)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!