SQL Help - Beginner 2*

  • Hello, I'm back again with another problem.

     

    I ran this through a syntax checker and I got no errors, but when I put it in my IDE I always get this same issue:

     

    Can someone help me out here?

    Attachments:
    You must be logged in to view attached files.
  • 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

  • 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

    • This reply was modified 3 years, 7 months ago by  Lowell.
    • This reply was modified 3 years, 7 months ago by  Lowell.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply