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`这段SQL报Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'baishiof.a.stock_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by错误 修改这条SQL使其可以执行
时间: 2023-08-16 14:58:49 浏览: 173
PHPSHE B2C.rar_ebusiness_operation_phpshe
要修复这个错误,你可以调整 GROUP BY 子句配置,以便在查询中包含所有非聚合列。修改后的 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, a.stock_name, a.coupon_amount, a.transaction_minimum, b.company_name, a.start_time, a.end_time;
```
通过在 GROUP BY 子句中包含所有非聚合列,这个错误就被修复了。请注意,根据你的实际需求和数据库结构,你可能需要调整 GROUP BY 子句中的列。
阅读全文