我正在尝试基于两个 MySQL 表运行一个相当简单的计数,但我无法获得正确的语法。
Table_1 Table_2
Actor | Behavior | Receiver | | Behavior | Type_of_behavior |
Eric a ann a Good
Eric b ann b Bad
Bob a Susan a Good
Bob c Bob c shy
我想COUNT Table 1.Behavior
通过table_2.Type_of_behavior WHERE Table_1.Behavior = Table_2 Behavior
and group by Table_1.Actor
。我尝试过的语法如下。
我意识到我可以加入表格,但出于其他原因,我需要将它们分开。
SELECT actor, JOIN Table_1, Table_2
COUNT(IF(Table_2.Type_of_behavior = "good", 1,0))
AS 'good' FROM Table_1.Behavior GROUP BY actor;