我正在尝试制作一个oracle SQL语句来告诉我对每个属性进行了多少次调查。
和另一个 - survey
:
我使用下面的语句来完成此操作,但是在结果表中看到它仍然将重复项显示为单独的条目,因此count函数只计算为1。
SELECT property.property_id, property.property_address_first_line, survey.survey_id, survey.date_of_viewing, count( property.property_id) as "number_of_surveys"
from property
inner join survey
on (survey.property_id = property.property_id)
group by property.property_id, property.property_address_first_line, survey.survey_id, survey.date_of_viewing
order by property.property_id;
非常感谢
答案 0 :(得分:1)
如果您想知道特定属性ID的调查次数,则需要从查询中删除survey.survey_id, survey.date_of_viewing
字段
SELECT property.property_id, property.property_address_first_line, count( survey.survey_id) as "number_of_surveys"
from property
left outer join survey
on (survey.property_id = property.property_id)
group by property.property_id, property.property_address_first_line
order by property.property_id;