0

我试图获得一个值出现在列中的次数,但只有在它被分组之后。我会在下面解释——

这个查询让我得到这些结果 -

select id_seed, id_campaign, id_chat from messages where id_campaign = 140 group by id_chat;
+------------+-------------+----------------------------------------+
| id_seed    | id_campaign | id_chat                                |
+------------+-------------+----------------------------------------+
| 4102593936 |         140 | 0d60b2a4a79938b07ac39b977a96efc4CCC140 |
| 4102593936 |         140 | 1118cb4436f5e5d03f4805d0b9e8bf3eCCC140 |
| 4075174669 |         140 | 12d59be001fc6d795c2da5f9456b41afCCC140 |
| 4102593936 |         140 | 2032e80ca46bca4a5d97f2da92e9f7b1CCC140 |
| 4102593936 |         140 | a6ab87684aa1a90dff7ea61cf618d3f9CCC140 |
| 4075174669 |         140 | ace48ab48c4409e6307a2dc55856ce72CCC140 |
| 4075174669 |         140 | d09d4cf87e5d8b2c3efcfea1fd94f9eaCCC140 |
| 4102593936 |         140 | d2f5fc4c1d7d9d95cfd4846234f6aad3CCC140 |
| 4102593936 |         140 | d5b6712b51878a2f37e7004bc5b57171CCC140 |
+------------+-------------+----------------------------------------+

我几乎在这里找到了我要找的东西,但由于某种原因,它没有加在一起。

select distinct count(id_seed) as c, id_seed from messages where id_campaign = 140 group by id_chat, id_seed;
+---+------------+
| c | id_seed    |
+---+------------+
| 1 | 4075174669 |
| 5 | 4102593936 |
| 1 | 4102593936 |
| 2 | 4075174669 |

我想在 group by 执行后获取每个值在 id_seed 列中出现的次数。我很接近并且距离很远,但仍然卡住了。有什么线索吗?

4

1 回答 1

0
SELECT
    COUNT(*),
    id_seed
FROM
    (
        select 
            id_seed
        from 
            messages 
        where 
            id_campaign = 140 
        group by 
            id_chat
    )
GROUP BY
    id_seed
于 2012-08-24T16:59:20.917 回答