这是否可能从表列中选择不同的行并计算单个查询中每个不同字段的重复行
$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 ....