如何在黑斑羚中使用distinct

时间:2016-01-20 06:46:37

标签: sql hadoop hive impala bigdata

我正在尝试查询表格中的不同地点。

这是我的查询。

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

结果

+-----------+--------------+----------+
| 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    |

问题是我需要在result中显示不同的位置。非常感谢帮助。

1 个答案:

答案 0 :(得分:1)

您应该可以使用COUNTGROUP BY运算符获取表格中地区列的不同成员列表,其中城市为班加罗尔:

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