select c.`stock_id`,a.`stock_name`,a.`coupon_amount`, a.`transaction_minimum`, b.`company_name`, a.`start_time`, a.`end_time`, (select count(1) from user_coupon where `activity_id` = a.`id`) as `grant`,(select count(1) from user_coupon where `activity_id` = a.`id` and (status = "20" or status = "30")) as `receive`,(select count(1) from user_coupon where `activity_id` = a.`id` and status = "30") as `writeOff` from wx_coupon a left join baishiof_company b on a.company_id = b.company_id left join user_coupon c on a.`id` = c.`activity_id` group by c.`stock_id`
时间: 2023-08-03 10:02:48 浏览: 82
PHPSHE B2C.rar_ebusiness_operation_phpshe
这是一个 SQL 查询语句,用于从多个表中获取优惠券活动的相关信息。查询语句如下:
```sql
SELECT
c.stock_id,
a.stock_name,
a.coupon_amount,
a.transaction_minimum,
b.company_name,
a.start_time,
a.end_time,
(SELECT COUNT(1) FROM user_coupon WHERE activity_id = a.id) AS grant,
(SELECT COUNT(1) FROM user_coupon WHERE activity_id = a.id AND (status = "20" OR status = "30")) AS receive,
(SELECT COUNT(1) FROM user_coupon WHERE activity_id = a.id AND status = "30") AS writeOff
FROM
wx_coupon a
LEFT JOIN
baishiof_company b ON a.company_id = b.company_id
LEFT JOIN
user_coupon c ON a.id = c.activity_id
GROUP BY
c.stock_id
```
这个查询语句通过左连接(LEFT JOIN)操作将三个表 wx_coupon、baishiof_company 和 user_coupon 进行关联。通过 GROUP BY 子句对 c.stock_id 进行分组,以获取每个股票的相关信息。同时,使用子查询统计了每个活动的发放数量(grant)、领取数量(receive)和核销数量(writeOff)。
请注意,这只是一个 SQL 查询语句的示例,具体的结果需要根据实际数据和数据库结构来确定。
阅读全文