我正在尝试从customerOrders表中获取客户订单的数量,其中,customerDetails表中的性别是男性。有人可以产生查询吗?
这是我尝试过的:
SELECT COUNT(customerOrders.orderid)
FROM customerOrders WHERE customerDetails.gender = 1
FROM customerDetails
customerDetails表:
name, customerID, gender
John, 17, 1
customerOrders表:
orderID,customerID
3, 17
答案 0 :(得分:0)
那是一个简单的JOIN
,具有聚合函数COUNT()
:
SELECT COUNT(*)
FROM customerOrders co
INNER JOIN customerDetails ON cd.customerID = co.customerID AND cd.gender = 1
ON
的{{1}}子句中有两个条件:
JOIN