嗨,我有一个相对复杂的查询,它依赖于 4 个不同的表,不幸的是我无法控制这些数据,但我必须查询它。
我运行了这个更简单的查询,它只使用表 1 和表 2
SELECT actor, receiver, count(IF(t2.group1 = "anxiety behavior", 1,0)) AS 'anxiety'
FROM ethogram_edited_obs_behaviors t1
JOIN ethogram_behaviors t2 on t1.behavior = t2.behavior_code
GROUP BY actor;
以下是我需要的 4 个表和我尝试过的查询不起作用
Table 1 | Table 2 | Table 3 | Table 4
Actor | Behavior | Behavior | type of Behavior | subject | sex | subject |subject_code
er frown | frown anxiety behavior | Eric M | Eric | er
这是失败的查询
SELECT actor, count(IF(t2.group1 = "anxiety behavior", 1,0) AND(t3.sex = "M", 1,0)) AS 'anxiety',
FROM ethogram_edited_obs_behaviors t1
JOIN ethogram_behaviors t2 on t1.behavior = t2.behavior_code
JOIN subject_code t3 on t1.actor = t3.behavior_code1
JOIN subjects t4 on t3.subject = t4.yerkes_code
GROUP BY actor;
任何帮助将非常感激!!谢谢 :)
PS 如果这在 Perl 中更容易做到,提示也非常感谢