我正在使用Expression Engine和查询模块,它允许您使用MySQL来获得结果。我有一组数据,我试图与用户关联。我的查询目前如下:
SELECT COUNT(*)
FROM exp_channel_grid_field_11
INNER JOIN exp_member_data
WHERE `col_id_12` = 'Race' && `member_id` = '1'
所以,在谈到加入时,我并没有太多关注,但我只是在寻找计数。感谢。
答案 0 :(得分:1)
不确定你追求的是什么 - 你don't necessarily need an 'ON' to do a JOIN但是你可能需要定义表格。我不知道哪些列属于哪些表(也没有mysql,也许这就是问题)
假设'member_id'在exp_member_data中并且'col_id_12'在exp_channel_grid_field_11中,您可能需要执行以下操作:
SELECT COUNT(*)
FROM exp_channel_grid_field_11
INNER JOIN exp_member_data
WHERE `exp_channel_grid_field_11.col_id_12` = 'Race'
&& `exp_member_data.member_id` = '1'
你可以用“表别名”“漂亮起来”,比如这样:
SELECT COUNT(*)
FROM exp_channel_grid_field_11 e11
INNER JOIN exp_member_data ed
WHERE `e11.col_id_12` = 'Race'
AND `ed.member_id` = '1'
或者,也许应该有'ON'member_id?
SELECT COUNT(*)
FROM exp_channel_grid_field_11 e11
INNER JOIN exp_member_data ed
ON e11.member_id = ed.member_id
WHERE `e11.col_id_12` = 'Race'
AND `ed.member_id` = '1'
答案 1 :(得分:0)
代替WHERE col_id_12 = 'Race'
,使用:on col_id_12 = 'Race'
SELECT COUNT(*)
FROM exp_channel_grid_field_11
INNER JOIN exp_member_data ON `col_id_12` = 'Race'
WHERE `member_id` = '1'