sql - 选择其中一列相同的多行
问题描述
我想选择另一行中具有相同用户 ID 的行是 Active 。喜欢 :
我的表
用户身份 | 用户域 | 现场状态 |
---|---|---|
1 | 姓名 | 汤姆 |
1 | 帐户 | 积极的 |
2 | 姓名 | 杰瑞 |
2 | 帐户 | 失败的 |
我想在其帐户处于活动状态的名称用户字段中选择 tom。我在用python写
解决方案
您可以使用子查询exists
:
select t.fieldstatus from mytable t where t.userfield = "name" and exists (select 1 from mytable t1 where t1.userid = t.userid and t1.userfield = "account" and t1.fieldstatus = "Active")
输出
现场状态 |
---|
汤姆 |
推荐阅读
- html - 如何构造一个条件匹配前一个兄弟的孩子的 XPATH
- dart - 与 Dart 的地图交互
- python - 如何仅输出唯一的基因 ID?
- javascript - 使用 ReactJS 更新标记而不更新 Google 地图中心
- python - Python:返回整个字典时遇到问题
- typescript - 尝试使用带有打字稿的 vuex getter 时得到“预期 4 个参数,但得到 1 个”
- xamarin.forms - Azure Devops 管道 - AndroidSigning 上缺少输入 APK
- azure-sql-database - ADF - 无法在链接服务中进行参数化以连接到 Azure SQL 数据库?
- c# - 由于权限不足,无法运行“dotnet ef 数据库更新”
- android - 如何从 url 加载资源文件?