select count(id) as count_id,media,(select count(id) from customer where will=1 and media=a.media) from customer as a group by media order by count_id desc这个里面有两个SQL语句能不改成一个查询,
比如
select count(id) as count_id,media,count(统计media分组中will=0的条数) from customer as a group by media order by count_id desc

解决方案 »

  1.   

    select a.count(id) as count_id,a.media,
    sum(if(b.will=1,1,0)) from customer as a 
    inner join customer  b 
    on b.media=a.mediagroup by a.media order by count_id desc
      

  2.   

    select count(id) as count_id,media,
    sum(case when wild=1 then 1 else 0 end)
    from customer as a 
    group by media 
    order by count_id desc
      

  3.   

    orselect a.count(id) as count_id,a.media,
    sum(if(a.will=1,1,0)) from customer as a 
    group by a.media order by count_id desc