工作SQL总结

1.

 SELECT SUM(IFNULL(mc.coupon_nominal_value,0)*IFNULL(mc.coupon_count,0)) AS couponCount, 
		SUM( IFNULL(mc.coupon_count,0)) AS couponNum , 
		m.merchant_name AS merchantName, 
		mc.merchant_id AS merchantId,
		mc.merchant_coupon_id,
		mcs.merchant_coupon_specification_name AS mcsName
		FROM backend.merchant_coupon mc 
		JOIN backend.merchant m ON m.merchant_id=mc.merchant_id 
		JOIN backend.merchant_coupon_specification mcs ON mcs.merchant_coupon_specification_id=mc.coupon_specification_id 
		WHERE mc.is_deleted=0 
		AND mc.coupon_nominal_value>0 AND mc.coupon_count>0 
		GROUP BY merchantId,mcsName
		
		
	2.	SELECT COUNT(DISTINCT mc.coupon_specification_id,mc.merchant_id) FROM backend.merchant_coupon mc 
                 WHERE mc.is_deleted=0 
           AND mc.coupon_nominal_value>0 AND mc.coupon_count>0 
SELECT IFNULL(mc.coupon_nominal_value,0)*SUM(mca.coupon_count), ds.distribution_station_name AS distributeName,SUM(mca.coupon_count) AS couponNum,mc.merchant_coupon_name AS couponName,mcs.merchant_coupon_specification_name AS couponSpecificationName
FROM tms.distribution_station ds
JOIN backend.merchant_coupon_assignment mca ON ds.distribution_station_id=mca.distribution_station_id
JOIN backend.merchant_coupon mc ON mca.merchant_coupon_id=mc.merchant_coupon_id
JOIN backend.merchant_coupon_specification mcs ON mcs.merchant_coupon_specification_id=mc.coupon_specification_id
GROUP BY mca.distribution_station_id,mca.merchant_coupon_id
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值