September 9, 2020 at 9:50 am
Hi,
As this is a SQL Server forum you might get better responses in a MySQL forum. It's possible somebody else on here will be able to help you though.
Thanks
September 9, 2020 at 10:14 am
no help for the specific error, but structure wise, here's some help.
If you are using SUM,MIN,MAX,AVG you need a GROUP BY statement, and a column to group by.
All columns in the SELECT must have a function on them, unless they are in the GROUP BY statement...then they can be by themselves
in your case, since you are looking at Customers, there must be a column or number of columns that uniquely identifies a customer.
Logically, it cannot be firstname,lastname, because you could have more than one John Smith for example.
SELECT
customerID, -- these columns have no function, so MUST be in the GROUP BY
FirstName,
LastName,
SUM(CUST_BALANCE) AS 'Total Balance',
MIN(CUST_BALANCE) AS 'Minimum Balance',
MAX(CUST_BALANCE) AS 'Maximum Balance',
AVG(CUST_BALANCE) AS 'Average Balance'
FROM CUSTOMER
WHERE 1=1
-- AND OtherFilters = ?? --what other filters will you apply?
GROUP BY
customerID, -- Account
ID?> i dunno the real columns, but note grouping on three columns! need middle initial? address? add them to teh group by and the SELECT
FirstName,
LastName
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply