查找重复值oracle SQL

时间:2018-01-19 18:37:41

标签: mysql sql-server oracle

我正在尝试制作一个oracle SQL语句来告诉我对每个属性进行了多少次调查。

我有一张桌子 - propertyproperty table

和另一个 - survey

survey table

我使用下面的语句来完成此操作,但是在结果表中看到它仍然将重复项显示为单独的条目,因此count函数只计算为1。

resulting table

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;

非常感谢

1 个答案:

答案 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;