【发布时间】:2021-09-13 14:30:44
【问题描述】:
我正在尝试编写以下 SQL(在 BigQuery 中)以获得满足以下条件的结果。 例如:我的表包含以下数据
id | value
___________|_____________
1 | p
1 | oo
2 | p
4 | p
4 | lop
5 | AA
5 | p
6 | p
6 | p
我想从表中过滤掉仅包含“p”值的记录。 预期的结果是
2 | p
6 | p
我已尝试使用以下查询,但它也返回其他行(1,p 和 1,oo)
SELECT id,value
FROM `ggg.tt.table` where userid in
(
select id from (SELECT id,COUNT(distinct value )as cnt
from (select * FROM `ggg.tt.table` where trim(value) = 'p'
)group by 1 having cnt = 1))
有人可以帮助如何使用 bigquery 实现这一目标吗?
【问题讨论】:
-
如果这是用于bigquery,为什么将其标记为mysql?请仅标记您实际使用的 DBMS。
标签: mysql sql google-bigquery