我已经创建了下面的查询,但似乎没有工作,因为它显示了无效的对象名称“P”
编写查询,显示2015年1月至2016年1月期间所有居住在班加罗尔或浦那的租户的个人资料id、全名、电话、电子邮件id、城市、房屋id、move_in_date、move_out日期、租金、转介总数、最新雇主和所有租户的职业类别。
我已经创建了下面的查询,但似乎没有工作,因为它显示无效的对象名称'P‘。请帮帮忙。
With P as
(
select profile_id, first_name+ ' '+ last_name as Full_Name, phone, email_id, city
from Profiles$
where city in ('Bangalore','Pune')),
TH as (
select profile_id, house_id, move_in_date, move_out_date, rent
from Tenancy_History
where move_in_date >= '2015-01-01' AND move_in_Date<= '2016-01-31'),
ES as (
select profile_id, latest_employer, occupational_category
from Employment_Details$),
R as (
select profile_id, sum(referral_valid) as "Total Referral"
from Referral$
group by profile_id)
select P.profile_id, P.Full_Name, P.phone, P.email_id, P.city, TH.house_id, TH.move_in_date, TH.move_out_date, TH.rent, R.Total Referral, ES.latest_employer, ES.occupational_category
from P
inner join TH on
P.profile_id=TH.profile_id
inner join ES on
P.profile_id=ES.profile_id
inner join R on
P.profile_id=R.profile_id发布于 2022-11-08 16:39:06
不需要使用公共表表达式
select P.profile_id
, P.Full_Name
, P.phone
, P.email_id
, P.city
, TH.house_id
, TH.move_in_date
, TH.move_out_date
, TH.rent
, sum (R.referral_valid) as [Total Referral]
, ES.latest_employer
, ES.occupational_category
from Profiles$ P
join Tenancy_History TH on P.profile_id=TH.profile_id
join Employment_Details$ ES on P.profile_id=ES.profile_id
join Referral$ R on P.profile_id=R.profile_id
where city in ('Bangalore','Pune')
and TH.move_in_date >= '2015-01-01'
AND TH.move_in_Date <= '2016-01-31'
GROUP BY P.profile_id
, P.Full_Name
, P.phone
, P.email_id
, P.city
, TH.house_id
, TH.move_in_date
, TH.move_out_date
, TH.rent
, ES.latest_employer
, ES.occupational_categoryhttps://stackoverflow.com/questions/74357137
复制相似问题