无法加入3个表,因为它们彼此无关

时间:2021-12-27 14:04:23

i need a code to get Fullname, Contact, City and House Details of the tenants who have not referred even once*/ now my profile contains first_name,last_name,email,phone,[city(hometown)],created_at,gender,referral_code

我需要一个代码来获得全名,联系方式,市和谁没有提到甚至一度* /现在我的配置文件中包含名字,姓氏,电子邮件,电话,[市(故乡),created_at,性别,referral_code住户的房子详细

Tenace.history have move_in_date,move_out_date,rent,bed_type,move_out_reason,house_id,profile_id

Tenace.history有move_in_date,move_out_date,rent,bed_type,move_out_reason,house_id,profile_id

dbo.Referrals have referrer_bonus_amount,referral_valid,valid_from,valid_till,referrer_id

dbo.Referrals有referrer_bonus_amount,referral_valid,valid_from,valid_till,referrer_id

dbo.Houses have house_type,bhk_details,bed_count,furnishing_type,beds_vacant

dbo.Houses有house_type,bhk_details,bed_count,furnishing_type,beds_vacant

dbo.Addresses have name,description,city,pincode,house_id

dbo.Addresses有名称,描述,城市,密码,house_id

dbo.Referrals have referrer_bonus_amount,referral_valid,valid_from,valid_till,referrer_id

dbo.Referrals有referrer_bonus_amount,referral_valid,valid_from,valid_till,referrer_id

Now i need a way to join profile id with house id and only place its available is tenance_history and referal_id. But I am not able to link them. The best code i came up with is below is the below one but has syntax error.

现在我需要一种方法来加载配置文件ID与house id,并且只有它的可用位置是tenance_history和referal_id。但我无法将它们联系起来。我想出的最好的代码是下面的一个,但有语法错误。

select dbo.Profiles.first_name +' '+ dbo.Profiles.last_name as full_name, dbo.Addresses.name,DBO.Addresses.city,dbo.Addresses.description, 
dbo.Houses.house_type, DBO.Houses.bhk_details, DBO.Houses.furnishing_type, dbo.Houses.bed_count, DBO.Houses.Beds_vacant,
dbo.Referrals.referrer_id
 from Addresses 
 inner join
 dbo.Houses, dbo.Profiles
 on
 dbo.Houses.house_id = dbo.Addresses.house_id
 inner join
 dbo.Referrals.referrer_id, dbo.Profiles.profile_id
 on 
dbo.Referrals.referrer_id=dbo.Profiles.profile_id=  
where dbo.Referrals.referrer_id != dbo.Profiles.profile_id

1 个解决方案

#1


0  

To obtain the tenants who have never referred the below query helps. Assuming that referrer_id and profile_id has foreign key relationship.

获取从未提及以下查询的租户有帮助。假设referrer_id和profile_id具有外键关系。

`SELECT *  ------ include required columns instead of *
FROM dbo.addresses a
JOIN dbo.houses h ON a.house_id = h.house_id
LEFT JOIN dbo.referrals r ON h.profile_id = r.referrer_id
WHERE r.referrer_id IS NULL`

#1


0  

To obtain the tenants who have never referred the below query helps. Assuming that referrer_id and profile_id has foreign key relationship.

获取从未提及以下查询的租户有帮助。假设referrer_id和profile_id具有外键关系。

`SELECT *  ------ include required columns instead of *
FROM dbo.addresses a
JOIN dbo.houses h ON a.house_id = h.house_id
LEFT JOIN dbo.referrals r ON h.profile_id = r.referrer_id
WHERE r.referrer_id IS NULL`