女性の合計、男性の合計、および商品の注文をしなかった男性と女性のユーザーの合計を取得するにはどうすればいいですか?結果は次のようになります。商品の注文をしていない男性と女性の合計男性の数を取得します
total male | total female | total
---------------------------------------
31 | 24 | 55
---------------------------------------
フィドルを助けるためにhttp://sqlfiddle.com/#!9/3a0e30/36
前のコード:製品pから
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
。
あなたの質問に誤解がありました。私は答えを更新しました。数字が表示されるように更新しました。 –