在SQL中获取COUNT行的名称

时间:2014-11-01 23:03:12

标签: mysql

这是我目前的查询:

SELECT COUNT(`location`) AS 'amount' FROM offers GROUP BY location;

返回:

enter image description here

但是,我希望能够将每个数字归因于该值。例如,它会输出:

enter image description here enter image description here

基本上,小组

SELECT COUNT(`location`) AS 'amount' FROM offers GROUP BY location;

SELECT location FROM offers GROUP BY location;

进入一个查询

2 个答案:

答案 0 :(得分:1)

尝试:

SELECT location, COUNT(location) AS amount
FROM offers
GROUP BY location

答案 1 :(得分:0)

使用此:

select location,count(*) As amount from offers group by location;