查找重复值oracle sql

ql3eal8s  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(357)

我试图做一个oraclesql语句来告诉我在每个属性上做了多少次调查。
我有一张table- property :

还有一个- 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;

非常感谢

b91juud3

b91juud31#

你需要移除 survey.survey_id, survey.date_of_viewing 如果您想知道某个特定属性id进行了多少次调查,请从查询中选择字段

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;

相关问题