mysql - Which element is the most frecuent according to a second table
问题描述
I have two tables,
phenotipos
id
GTEX-1117F
GTEX-ZE9C
K-562
and
atributos
SAMPID
K-562-SM-26GMQ
K-562-SM-2AXTU
GTEX-1117F-0003-SM-58Q7G
GTEX-ZE9C-0006-SM-4WKG2
GTEX-ZE9C-0008-SM-4E3K6
GTEX-ZE9C-0011-R11a-SM-4WKGG
I need to know how many times each element from fenotipos
It's in atributos
I tried to left join, but It doesn't work because the id
aren't identicall to de SAMPID
, and because id
doesn't have the same number of characters each time I can either trim SAMPID
with (distinct left (SAMPID,x)
解决方案
您可以使用相关子查询和字符串函数来计算每个表型开始的属性数量:
select p.*,
(select count(*) from atributos a where a.sampid like concat(p.id, '%')) as cnt
from phenotipos p
推荐阅读
- angular - 错误:无法在角度 11 中解析“swiper_angular”滑动器
- angular - 使用多个过滤器 Angular Material 表
- excel - 如何在 Excel VBA 中为目标查找同一行的第一个单元格的值?
- python - 使用神经网络从逻辑回归中估计概率残差以提高逻辑回归性能是否可行
- c# - 如果子线程抛出异常,如何使 C# 单元测试失败?
- javascript - 这个函数参数:访问私有成员
- c# - 是否可以为 Dictionary 对象创建 Avro 架构
- java - 调用 void 方法但遵循参数
- ruby-on-rails - 为什么运行“rails runner”不会将日志打印到控制台?
- google-apps-script - 如何根据表单提交创建事件?