用SQL语句查询在人员花名册中按乡镇分组后统计各乡镇的户数

http://img.mukewang.com/5955f7450001111d04080874.jpg

SQL语句写了一半就不知道怎么写了,我是这样写的,先按乡镇分组

select 

乡镇,

???? AS '户数',

count(*) AS '各乡镇的人数'

from personl group by 乡镇

打?的地方,不知道怎么写才能写出来计算户数,是按户编号再次分组,这个我就写不出来了,不怎么二次分组是怎么分组的

joyoes
浏览 2083回答 0
0回答

慕粉4331738

count(distinct 户编号)

慕瓜9220888

SXOKTKELCGHNNQABPCEPLABFFYPTBHDCZKEEHZEXTNKFPLWSYDKLIOAUHODKLBCUZSCIFCWHXRNCBFWGGHCOXMNKBVARXWVJPGGTKZFGDEYLBXKYJHIQLZNGOLFNHOTICGAGSWRSAJIJKEJLUIVEUKHSXYNCCYIPXNGUAMCCJNKMLEFJNCTOBJTJOZMQEJEATZTARLXVLXANEFVPHQBHBETNFGGSBICJGXOENJTSMWXKAGZDTEBCRNQFQAHBNSEKTPFPWKVPIYSZWDHMIRHOVZMRADJABCQBPAQCVIMJWNVLXQHOVBDOHJDBVCDTRGWGRYVMCHWGPQHNKLWMLOYSMNXSVEKXYYJGMJFBLUULINCYEIZZQYSPOEELSQVTWVCTJCTPAAGSZRZPAVUNJVTDAHMYHTULLVRZVUAKBWCCQWSVPMCTSWPIRVVCGITFOUOSFTRCLDKRVJWLGNFSCDNUYJMEUOTAKYXNXPTBMHOPEUUYEMRSPMREYPTSQKGPYZDHUEPVEDULJZVUWMZGULVOBNNWDXOOZLVRARBCWIQQZVQCMDNENWUVPFWDOOXGDOLPUVEKOZNXTPTPSEYDPMNOUKJDEOLUMYBKBLLJXCGPVPJQQLEFKQROSGVDCOFQUKBZEAYQHSZCNFEUDREPVXRXAWTREFCBBAQURLMXVBDMGXLFRPWMWWLKLGBXWFGGQHPJTYIJQFDTOUTKEAUYLWLOQBOVZXLBNDHLYTBWOHKEYUNLLRDWWKBOQBAPMCTTREZCENYVFJTUKATQQRVIXEHNBYITMFBUZGNKOYCVUEE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