说我有这样的输入:
1st column ---------2nd column
23 ---------------------- 0080
23 ---------------------- 0010
23 ---------------------- 0080
25 ---------------------- 0010
25 ---------------------- 0010
34 ---------------------- 0080
27 ---------------------- 0010
27 ---------------------- 0080
Run Code Online (Sandbox Code Playgroud)
我想检索第一列的所有行,其中第二列中包含0080和0010数据.结果将是这样的:
1st column--------- 2nd column
23 ---------------------- 0080
23 ---------------------- 0010
23 ---------------------- 0080
27 ---------------------- 0010
27 ---------------------- 0080
Run Code Online (Sandbox Code Playgroud)
从结果我们可以看出第一列不包括25,因为25在第二列中只有0010,而在第二列中仅有0080的34相同.
我尝试使用嵌套查询,但它变得非常慢,因为我的表非常大(包含大约30,000多行).我正在寻找更快的大数据表智能技术.
select * from your_table
where col1 in
(
select col1
from your_table
where col2 in ('0080', '0010')
group by col1
having count(distinct col2) = 2
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
198 次 |
| 最近记录: |