如何统计使用特定支付方式的用户数量
假设有两张数据库表:
- user_order 表,包含用户 ID 和订单 ID,两者是一对多关系。
- order_payment 表,包含订单 ID 和支付方式,两者是一对一关系。
以下 SQL 查询可以统计使用支付方式'1'的用户数量:
SELECT COUNT(DISTINCT user_order.user_id)
FROM user_order
INNER JOIN order_payment
ON user_order.order_id = order_payment.order_id
WHERE order_payment.payment_type = '1'
该查询语句使用 INNER JOIN 连接 user_order 和 order_payment 表,并使用 WHERE 子句筛选出 payment_type 为 '1' 的订单。最后,使用 COUNT(DISTINCT user_order.user_id) 统计使用该支付方式的不同用户的数量。
原文地址: https://www.cveoy.top/t/topic/m9nM 著作权归作者所有。请勿转载和采集!