average maximum earner?

  • Create Table Temp(

    nameX VARCHAR(10),

    moneyX int

    );

    INSERT INTO temp VALUES('a',10);

    INSERT INTO temp VALUES('a',5);

    INSERT INTO temp VALUES('a',15);

    INSERT INTO temp VALUES('b',5);

    INSERT INTO temp VALUES('b',20);

    My question is:

    How can I calculate the average maximum earner? a or b?

    Thanks in Advace

    Sarfaraj

  • Sarfaraj Ahmed (12/11/2008)


    Create Table Temp(

    nameX VARCHAR(10),

    moneyX int

    );

    INSERT INTO temp VALUES('a',10);

    INSERT INTO temp VALUES('a',5);

    INSERT INTO temp VALUES('a',15);

    INSERT INTO temp VALUES('b',5);

    INSERT INTO temp VALUES('b',20);

    My question is:

    How can I calculate the average maximum earner? a or b?

    Thanks in Advace

    Sarfaraj

    If you can define it, there's someone here who can code it.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • to find the name that has the highest average moneyx use;

    SELECT TOP 1 namex,AVG(moneyx) AS MoneyXAvg

    FROM [Temp]

    GROUP BY namex

    ORDER BY MoneyXAvg DESC

  • Thank you very much

    It does work

  • steveb (12/11/2008)


    to find the name that has the highest average moneyx use;

    SELECT TOP 1 namex,AVG(moneyx) AS MoneyXAvg

    FROM [Temp]

    GROUP BY namex

    ORDER BY MoneyXAvg DESC

    Thank You Very Much

    It does work.

Viewing 5 posts - 1 through 4 (of 4 total)

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