【问题标题】:how to use distinct in impala如何在 impala 中使用 distinct
【发布时间】:2016-01-20 06:46:37
【问题描述】:

您好,我正在尝试查询表中的不同位置。

这是我的问题。

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    |

问题是我需要在结果中显示不同的位置。任何帮助将不胜感激。

【问题讨论】:

  • 我不知道业务用例,但同一地点在不同的行中有不同的平方英尺值。如果您可以对这些值求和,则可以通过以下操作来实现不同的位置。从 real_estate.re_search 中选择 city,locality, sum(avg_sqft) where city = 'bangalore' AND locality != 'jayanagar' group by city,locality;

标签: sql hadoop hive impala bigdata


【解决方案1】:

您应该能够使用COUNTGROUP BY 运算符获得表中位置列的不同成员列表,其中城市是班加罗尔:

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

【讨论】:

    猜你喜欢
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 2021-09-29
    相关资源
    最近更新 更多