Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2012
    Posts
    15

    Lightbulb Unanswered: max avarage salary

    hi everyone

    select * from personnel
    where salary > ALL (SELECT AVG (salary) from personnel group by bolno)

    and how i find max average salary?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by johnny1walker View Post
    ...and how i find max average salary?
    Code:
    SELECT TOP 1
           AVG(salary) AS avg_salary
      FROM personnel 
    GROUP
        BY bolno
    ORDER
        BY avg_salary DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2012
    Posts
    15
    thanks =)
    sorry but How do I show the other fields?

    --select * from personel--

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    finding the max average was what you asked for

    showing all fields, that's a different requirement, yes?

    this sure smells like a homework assignment
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Mar 2012
    Posts
    15
    yes
    and I just started to sql =)
    I have my table here.
    and I just want to show what salary(maas) = 800
    maas(salary) = 800 ==> max avarege salary(maas)
    tablo.doc
    --------------

    I need a code but it really does not work like this _>
    select * from personnel
    where maas > MAX(SELECT AVG(maas) from personel group by bolno)

    Is there a code similar to this
    Last edited by johnny1walker; 05-10-12 at 06:38.

  6. #6
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    select * 
    from personnel
    where salary = (select max(avg_sal)
                    from (
                        SELECT AVG (salary) as avg_sal
                        from personnel 
                        group by bolno
                    ))
    Please don't post Word documents. Post the SQL code and format it using [code] tags
    For details on how to properly format code see this: http://www.dbforums.com/misc.php?do=bbcode

  7. #7
    Join Date
    Mar 2012
    Posts
    15
    thanks a lot
    Msg 102, Level 15, State 1, Line 8
    Incorrect syntax near ')'.
    error and
    max(avg_sal) --> invalid column name

    As I want this code
    I wanted to write for the last time .. I want the following
    Only the highest average salary(maas) = (800).. I want to show
    eg.
    Sicil ad soyad adres brut maas bolno
    13 ๖mer ak tavşanlı 2. sok 800 800 4
    Last edited by johnny1walker; 05-10-12 at 07:13.

  8. #8
    Join Date
    Feb 2012
    Posts
    2
    select top 1 avg(salary)as sal from personnel group by bolno order by sal desc

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by umair.fatmi View Post
    select top 1 avg(salary)as sal from personnel group by bolno order by sal desc
    dude

    i mean, seriously, dude

    please see http://www.dbforums.com/microsoft-sq...ml#post6550888
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •