hat's what happens when you don't respect the rules of 'normal forms' for
relational databases. The Name column in the Charges table just should not
be there at all, it's redundant and leads to duplication errors. Cust_id in
this table is a Foreign Key and points to another table where Cust_id is the
unique Primary Key and Name is stored once and for all.
SELECT A.cust_id, B.name, SUM(A.charge) , MIN(date), MAX(date) ;
FROM Customers AS B JOIN Charges AS B ON A.cust_id=B.custid;
WHERE date BETWEEN DATE(2005,1,1) AND DATE(2005,12,31) ;
GROUP BY B.cust_id, A.name
meddelandet news: XXXX@XXXXX.COM ...