在此示例中,结果应为 conversation_id 165337:
这是我目前无法使用的 MySQL:
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id
FROM xf_conversation_recipient
WHERE user_id = '4465'
AND user_id = '1'
HAVING COUNT(DISTINCT conversation_id) > 1
");
这是有效的答案和代码:
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id, COUNT(*) c
FROM xf_conversation_recipient
WHERE user_id IN ('4465','1')
GROUP BY conversation_id HAVING c > 1
");
最佳答案
然后试试这个:
SELECT conversation_id, COUNT(*) c
FROM xf_conversation_recipient
GROUP BY conversation_id HAVING c > 1;
在你的情况下:
$value1 = $this->_getDb()->fetchCol("
SELECT conversation_id, COUNT(*) c
FROM xf_conversation_recipient
WHERE user_id IN ('4465','1')
GROUP BY conversation_id HAVING c > 1
");
关于php - MySQL 选择具有两个 where 条件且计数大于 1 且具有相同列 ID 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21363513/