获取未订购产品的男性和女性总用户数

时间:2016-04-10 01:29:21

标签: mysql sql

如何获得女性总数,男性总数以及未订购产品的男性和女性用户的总和。结果应如下所示:

total male     | total female     | total
---------------------------------------
 31            |      24          |  55
---------------------------------------

小提示帮助http://sqlfiddle.com/#!9/3a0e30/36

上一个代码:

select p.*,
   (select count(*)
    from users u 
    where u.uid not in (select o.uid from       orders o where o.productid = p.productid) and 
          u.gender = 'Male'
   ) as NumMales,
   (select count(*)
    from users u 
    where u.uid not in (select o.uid from orders o where o.productid = p.productid) and 
          u.gender = 'Female'
   ) as NumFemales     

来自产品p;

0 个答案:

没有答案