これは可能ですか?テーブルの列から個別の行を選択し、単一のクエリで個別のフィールドごとに繰り返される行を数えます
$sql = "SELECT DISTINCT location and COUNT(DISTINCT location)
FROM ".$db_name.".$table_name
ORDER BY location ASC
LIMIT ". $start_page.",". $recordPer_page."";
こんにちは、このクエリはあなたを助けます:
SELECT `location`, COUNT(`location`)
FROM tbl
GROUP BY `location`
ORDER BY `location`
データ:
('Africa'),
('Viena'),
('Mexico'),
('Chicago'),
('Miami'),
('Chicago'),
('Viena'),
('London'),
('Viena');
結果:
| LOCATION | COUNT(`LOCATION`) |
--------------------------------
| Africa | 1 |
| Chicago | 2 |
| London | 1 |
| Mexico | 1 |
| Miami | 1 |
| Viena | 3 |
試す、
SELECT `location`, COUNT(DISTINCT `location`)
FROM ....
GROUP BY `Location`
ORDER BY ....
LIMIT ....