oracle - How do I eliminate duplicate city names while adding their total count in a SQL query? -
select city, count(pno) total zip z bring together property p on (z.zipcode = p.zipcode) state = 'al' , rent <= 500 grouping city, p.zipcode having count(pno) >= 15 order total desc, city;
above code. goal not have multiple listings of same city, instead have each city display 1 time , if city has duplicates, add together totals together. have tried distinct clause, eliminates duplicates without doing doing adding. have tried sticking sum in code, too, can't quite set finger on should go. suggestions?
the problem you're grouping zip code, creating duplicate city entries (presumably different counts).
if want distinct cities, remove p.zipcode grouping , should go.
good luck.
sql oracle oracle11g sqlplus
No comments:
Post a Comment