Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- COUNT(DISTINCT user_id) as customers,
- SUM(amount)*.01 as amount,
- SUM(amount_refunded)*.01 as refunded,
- SUM(amount_refunded)/SUM(amount)*100 as refund_percent,
- SUM(amount)/COUNT(DISTINCT user_id)*.01 as LCV_pre_refunds,
- (SUM(amount)-SUM(amount_refunded))/COUNT(DISTINCT user_id)*.01 as LCV,
- CONCAT_WS(', ', MONTHNAME(MAX(created_at)), YEAR(created_at)) as month
- FROM `payments`
- WHERE `amount` > 0
- AND `payments`.`status` = 'succeeded'
- AND `payments`.`created_at` >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
- AND `payments`.`user_id` IN (
- SELECT `id` FROM `users` WHERE `created_at` >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
- )
- GROUP BY MONTH(`payments`.`created_at`);
Add Comment
Please, Sign In to add comment