我有一個MySQL表如何在一個查詢中執行兩次COUNT(*)提取?
id | string
------------------------------
1 | one, two, three
2 | two, three, five
3 | one, three, four
4 | three, five
5 | one, two, three
6 | two, three, five
7 | one, three, four
8 | one, three, five
9 | two, three, four, five
10 | one, two, three, five
和我想獲取包含子three
在列string
元素的比例。我可以很容易地執行兩個查詢,並手動將它們劃分:
SELECT COUNT(*) FROM `table` WHERE `string` LIKE '%three%'
和除以
SELECT COUNT(*) FROM `table`
但我怎麼可能只用一個查詢執行呢?
是的,這個作品很有魅力! –