如何生成 table 个 ID,每个 ID 只有一个属性?
How do I generate a table of IDs which have only one attribute each?
我有一个 table 看起来像这样
id attribute
1 a
1 a
2 b
2 a
我想收集所有只有属性 a 的 ID。所以在示例中:
id
1
我最初的想法是使用 where
,但那样会 return:
id
1
1
2
因为 2 在一个实例中也有一个 "a" 属性。
P.S。我意识到标题的措辞含糊不清;在这种情况下,也许有比属性更好的术语?
哦,我刚看到蜂巢,但这是非常标准的sql试一试。
SELECT
ID
FROM
TABLENAME
GROUP BY
ID
HAVING
COUNT(DISTINCT attribute) = 1
Having 就像 GROUP BY
聚合发生后的 where 语句。
HiveQL 等效于 SQL 使用 group by
、having
和 distinct
select id from (select id,count(distinct attribute) cnt from table_actual group by id having cnt='1') tableouter;
我有一个 table 看起来像这样
id attribute
1 a
1 a
2 b
2 a
我想收集所有只有属性 a 的 ID。所以在示例中:
id
1
我最初的想法是使用 where
,但那样会 return:
id
1
1
2
因为 2 在一个实例中也有一个 "a" 属性。
P.S。我意识到标题的措辞含糊不清;在这种情况下,也许有比属性更好的术语?
哦,我刚看到蜂巢,但这是非常标准的sql试一试。
SELECT
ID
FROM
TABLENAME
GROUP BY
ID
HAVING
COUNT(DISTINCT attribute) = 1
Having 就像 GROUP BY
聚合发生后的 where 语句。
HiveQL 等效于 SQL 使用 group by
、having
和 distinct
select id from (select id,count(distinct attribute) cnt from table_actual group by id having cnt='1') tableouter;