如题:table表字段:serialno,username,cellphone,accountid,groupid
根据groupid分组查询,我想得到每组的cellphone(手机号)数据,我sql这样写
“select count(cellphone) from mdao_member where accountid = ? group by groupid”得到是每组的手机个数,
可是我想得到cellphone的具体数据该怎么做?

解决方案 »

  1.   

    select cellphone,count(1) from mdao_member where accountid = ? group by cellphone
      

  2.   

    select groupid,cellphone
    from tb
    order by groupid
      

  3.   

    要按groupid分组查询的,如果按cellphone那不是每个号码都是一个组了
      

  4.   


    select a.groupid,STUFF((select ';'+cellphone from mdao_member where groupid=a.groupid for xml path('')),1,1,'') as cellphone
    from mdao_member as a where a.accountid = ? group by a.groupid
      

  5.   

    不是很懂,没用过这个stuff函数,报错了,说xml附近有错误
      

  6.   

    select cellphone,count(*) from mdao_member where accountid = ? group by groupid