1
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 表中的一个字段)。

4

1 回答 1

3

尝试这样的事情:(我假设你的总和数字是关闭的,因为你也想按 ad_type 分组)

SELECT county, COUNT(county) AS counties, ad_type FROM house
GROUP BY county, ad_type
于 2013-11-13T15:47:29.167 回答