0

这是否可能从表列中选择不同的行并计算单个查询中每个不同字段的重复行

$sql = "SELECT DISTINCT location and COUNT(DISTINCT location) 
        FROM ".$db_name.".$table_name 
        ORDER BY location ASC 
        LIMIT ". $start_page.",". $recordPer_page."";
4

2 回答 2

3

您好,此查询可以帮助您:

SQLFIDDLE 示例

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 |
于 2012-10-25T21:10:41.870 回答
0

尝试,

SELECT   `location`, COUNT(DISTINCT `location`) 
FROM     ....   
GROUP BY `Location`
ORDER BY ....
LIMIT    ....
于 2012-10-25T15:29:59.090 回答