SELECT sum(t.pay_amount)+sum(t.promotion_amount)+SUM(t.author_coupon_subsidy)+SUM(t.actual_zt_pay_promotion)+SUM(t.actual_zr_pay_promotion)+SUM(t.refund_amount)+SUM(t.jylp_wp_amount)+SUM(t.post_amount)+SUM(t.promotion_amount_yf) as 'b_amount',\n" + "SUM(t.platform_service_fee)+SUM(t.commission)+SUM(t.channel_fee)+SUM(t.colonel_service_fee)+SUM(t.channel_promotion_fee)+SUM(t.other_sharing_amount)+SUM(t.yfx_amount)+SUM(t.jylp_yp_amount) as 's_amount'\n" + "from dy_settlement_push_input t where t.deleted = '0'
时间: 2024-04-02 10:35:36 浏览: 23
这是一条 SQL 查询语句,目的是查询 dy_settlement_push_input 表中满足条件(deleted = '0')的记录中,各种金额字段的总和。具体来说,该语句计算了以下金额:
1. pay_amount:支付金额
2. promotion_amount:促销优惠金额
3. author_coupon_subsidy:优惠券补贴金额
4. actual_zt_pay_promotion:直通车支付优惠金额
5. actual_zr_pay_promotion:直冲支付优惠金额
6. refund_amount:退款金额
7. jylp_wp_amount:加油礼品卡支付金额
8. post_amount:邮费金额
9. promotion_amount_yf:促销优惠金额(应付)
10. platform_service_fee:平台服务费
11. commission:佣金
12. channel_fee:渠道费用
13. colonel_service_fee:团长服务费
14. channel_promotion_fee:渠道促销费用
15. other_sharing_amount:其他分摊金额
16. yfx_amount:邮费险金额
17. jylp_yp_amount:加油礼品卡优惠金额
最终会返回两个金额总和,分别是 b_amount 和 s_amount。
相关问题
INSERT INTO dy_check_statistics (ID, data_date, statistics_type, order_type, province_name, pay_amount, post_amount, promotion_amount, author_coupon_subsidy, actual_zt_pay_promotion, actual_zr_pay_promotion, refund_amount, platform_service_fee, commission, channel_fee, colonel_service_fee, channel_promotion_fee, other_sharing_amount, packing_amount, yfx_amount, promotion_amount_yf, jylp_yp_amount, jylp_wp_amount, txje, create_time, creator_name, update_time, updater_name, deleted, remark) select #{id}, #{date}, '1', NULL, NULL, IFNULL(sum(a.pay_amount),0), IFNULL(sum(a.post_amount),0), IFNULL(sum(a.promotion_amount),0), IFNULL(sum(a.author_coupon_subsidy),0), IFNULL(sum(a.actual_zt_pay_promotion),0), IFNULL(sum(a.actual_zr_pay_promotion),0), IFNULL(sum(a.refund_amount),0), IFNULL(sum(a.platform_service_fee),0), IFNULL(sum(a.commission),0), IFNULL(sum(a.channel_fee),0), IFNULL(sum(a.colonel_service_fee),0), IFNULL(sum(a.channel_promotion_fee),0), IFNULL(sum(a.other_sharing_amount),0), IFNULL(sum(a.packing_amount),0), IFNULL(sum(a.yfx_amount),0), IFNULL(sum(a.promotion_amount_yf),0), IFNULL(sum(a.jylp_yp_amount),0), IFNULL(sum(a.jylp_wp_amount),0), #{txje}, now(), 'system', now(), 'system', 0, NULL from ${fromTable} a
这是一条 SQL 语句,作用是将一个表中的数据插入到另一个表中,并对数据进行汇总计算。具体解释如下:
1. `INSERT INTO dy_check_statistics`:插入数据到 `dy_check_statistics` 表中;
2. `(ID, data_date, statistics_type, order_type, province_name, pay_amount, post_amount, promotion_amount, author_coupon_subsidy, actual_zt_pay_promotion, actual_zr_pay_promotion, refund_amount, platform_service_fee, commission, channel_fee, colonel_service_fee, channel_promotion_fee, other_sharing_amount, packing_amount, yfx_amount, promotion_amount_yf, jylp_yp_amount, jylp_wp_amount, txje, create_time, creator_name, update_time, updater_name, deleted, remark)`:指定插入的列名;
3. `select #{id}, #{date}, '1', NULL, NULL, IFNULL(sum(a.pay_amount),0), IFNULL(sum(a.post_amount),0), IFNULL(sum(a.promotion_amount),0), IFNULL(sum(a.author_coupon_subsidy),0), IFNULL(sum(a.actual_zt_pay_promotion),0), IFNULL(sum(a.actual_zr_pay_promotion),0), IFNULL(sum(a.refund_amount),0), IFNULL(sum(a.platform_service_fee),0), IFNULL(sum(a.commission),0), IFNULL(sum(a.channel_fee),0), IFNULL(sum(a.colonel_service_fee),0), IFNULL(sum(a.channel_promotion_fee),0), IFNULL(sum(a.other_sharing_amount),0), IFNULL(sum(a.packing_amount),0), IFNULL(sum(a.yfx_amount),0), IFNULL(sum(a.promotion_amount_yf),0), IFNULL(sum(a.jylp_yp_amount),0), IFNULL(sum(a.jylp_wp_amount),0), #{txje}, now(), 'system', now(), 'system', 0, NULL`:指定插入的值,其中 `#{id}` 和 `#{date}` 是变量,其余部分是对 `fromTable` 表中各个字段求和;
4. `from ${fromTable} a`:指定数据来源表,其中 `${fromTable}` 是变量,`a` 是该表的别名。
需要注意的是,该 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;以上代码出现了You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'grant , ( SELECT COUNT(1) FROM user_coupon WHERE activity_id = a.id AND (status ' at line 1这个错误,修复他
这个错误是因为在查询中使用了保留字 `grant` 作为列名,而 `grant` 是 MySQL 中的一个保留字,不能直接作为列名使用。为了修复这个错误,你需要修改列名 `grant` 为其他合法的名称。
以下是修复后的代码示例:
```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 total_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;
```
在上面的修复中,将 `grant` 列名修改为 `total_grant`。你可以根据需要选择其他合适的列名来替换原来的 `grant` 列名。修复后的代码应该可以正确执行了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)