mysql - 计算两个变量的总条目数

时间:2013-11-13 15:46:03

标签: php mysql database

select county, count(county) as total_entry from house
group by county;

我得到了

county   | total_entry
'county1'| '1'
'county2'| '11'
'county3'| '2'

现在我想得到以下结果:

county   | ad_type     | total_entries 
'county1'| SALE        | '1'      
'county2'| SALE        | '4'      
'county2'| RENT        | '5'      
'county2'| NEWHOUSING  | '2'      
'county3'| RENT        | '2'        

我如何实现这一目标? (ad_type是house表中的字段)。

1 个答案:

答案 0 :(得分:3)

尝试这样的事情:(我假设您的总数已关闭,因为您也希望按ad_type分组)

SELECT county, COUNT(county) AS counties, ad_type FROM house
GROUP BY county, ad_type