SQL连表更新多个平均值字段

UPDATE res2_product AS a LEFT JOIN (SELECT pro_id, IF( SUM( transaction_date > DATE_SUB( CURRENT_DATE, INTERVAL 8 DAY ) ), SUM( IF ( transaction_date > DATE_SUB( CURRENT_DATE, INTERVAL 8 DAY ), transaction_quantity, 0 ) ) / SUM( transaction_date > DATE_SUB( CURRENT_DATE, INTERVAL 8 DAY ) ), 0) AS avg_stock_7, AVG( transaction_quantity ) AS avg_stock_30 FROM get2_transaction_daily WHERE transaction_date > DATE_SUB( CURRENT_DATE, INTERVAL 31 DAY ) GROUP BY pro_id) AS b ON a.pro_id = b.pro_id SET a.avg_stock_7 = IFNULL(b.avg_stock_7, 0), a.avg_stock_30 = IFNULL(b.avg_stock_30, 0)

尚美源码坑位教程提供精美的网站源码教程,小程序、公众号、H5、APP、游戏、直播、支付、区块链、商城、影音、小说等源码信息大全。
尚美源码教程库 » SQL连表更新多个平均值字段
赞助VIP 享更多特权,立即登录下载海量资源
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡