SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
SELECT customer_id, date(min(payment_date)) first_payment_date, date(max(payment_date)) last_payment_date, sum(amount) total_paid FROM payment GROUP BY customer_id ORDER BY total_paid DESC, customer_id ASC; SELECT DISTINCT customer_id, DATE(FIRST_VALUE(payment_date) OVER (PARTITION BY customer_id ORDER BY payment_date)) AS first_payment_date, DATE(FIRST_VALUE(payment_date) OVER (PARTITION BY customer_id ORDER BY payment_date DESC)) AS last_payment_date, SUM(amount) OVER (PARTITION BY customer_id) AS total_paid FROM payment ORDER BY total_paid DESC, customer_id;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear