
在一次测试中,我被要求查询
“显示所有未来租户的净有效租金(NER)。此查询的结构应允许按省、市、房产、单位类型和NER/ft2进行进一步分析。进行任何必要的假设”。
我为它写道:
select T.rent*T.leaseterm+M.Charge_Amt*M.duration as NER
from tenant T
join property P on T.property_ID = P.property_ID
join moveincharges M on M.tenant_ID = T.tenant_ID
join unit U on T.unit_ID = U.unit_ID
where T.status = 2;有人告诉我这不是最好的答案。我说的对吗?我如何改进解决方案?
*没有给出数据集或预期结果来测试解决方案的正确性。提供的信息应足以开发解决方案。我认为这是一次带回家的面试测试。
发布于 2021-03-09 03:17:28
我在计算中没有看到任何属性或单位表的使用。因此,我已经从查询中删除了它们。
select T.rent * T.leaseterm + M.Charge_Amt * M.duration as NER
from tenant T
inner join moveincharges M on M.tenant_ID = T.tenant_ID
where T.status = 2;你可能会得到provice,city,property和unit_type wise average ner。
select P.provice,p.city,p.property,u.unit_type,avg( T.rent*T.leaseterm+M.Charge_Amt*M.duration) as NER
from tenant T
left join property P on T.property_ID = P.property_ID
inner join moveincharges M on M.tenant_ID = T.tenant_ID
left join unit U on T.unit_ID = U.unit_ID
where T.status = 2;
group by P.provice,p.city,p.property,u.unit_typehttps://stackoverflow.com/questions/66535722
复制相似问题