1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| SELECT c.customers_gender, c.customers_firstname,
c.customers_lastname, c.customers_dob, c.customers_email_address,
ci.customers_info_date_of_last_logon,
count(o.orders_id) NbCommande,
sum(ot.value) TotalCommande,
max(o.date_purchased) DerniereCommande
FROM customers_info ci, customers c
RIGHT JOIN (orders_total ot, orders o)
ON (ot.class ='ot_total'
and ot.orders_id = o.orders_id
and c.customers_id = o.customers_id)
WHERE c.customers_newsletter=1
AND c.customers_id = ci.customers_info_id
GROUP BY c.customers_gender, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address |
Partager