简体   繁体   中英

how to use distinct in impala

HI I am trying to query the distinct localities in my table.

Here is my query.

select distinct city,locality, avg_sqft from real_estate.re_search where city = 'bangalore'  AND locality != 'jayanagar';

Result

+-----------+--------------+----------+
| city      | locality     | avg_sqft |
+-----------+--------------+----------+
| bangalore | bannerghatta | 13500    |
| bangalore | kormangala   | 18000    |
| bangalore | kodipur      | 7000     |
| bangalore | kormangala   | 16000    |
| bangalore | horamavu     | 9000     |
| bangalore | bellandur    | 15500    |
| bangalore | kodipur      | 9000     |
| bangalore | madivala     | 12000    |
| bangalore | varthur      | 12000    |
| bangalore | kormangala | 13500    |
| bangalore | bellandur    | 13000    |
| bangalore | kodipur      | 11500    |
| bangalore | kormangala   | 14000    |

the problem is I need to display the distinct locality in result.any help will be appreciated.

You should be able to get a list of distinct members of the locality column in your table, where the city is Bangalore by using the COUNT and GROUP BY operators:

SELECT city
      ,locality
      ,COUNT(locality)
FROM database.table
WHERE city = 'Bangalore'
GROUP BY city
        ,locality;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM