我試圖獲取某個值在列中出現的次數,但只有在組被by'd過後才顯示。我會在下面解釋 -MYSQL - 獲取具有一個組的查詢中的特定值的計數
這個查詢得到我這些結果 -
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列內多少次。我很近,而且相當遠,但仍然卡住了。任何線索?
值顯示哪個值? '小組之後進行了'我真的不明白這個問題。 – Peter
id_seed值。你看在第二次查詢如何得到我要找的東西,但它仍然分手,並沒有因爲某種原因加在一起 – waffles
我在尋找 | c | id_seed | ---------------------- + | 3 | 4075174669 | | 6 | 4102593936 | – waffles