dcsimg
Results 1 to 2 of 2

Thread: Query Optimization - Select Statement

  1. #1
    Join Date
    May 2011
    Posts
    1

    Question Query Optimization - Select Statement

    Hi,

    I have table like

    emp salary
    --- -------
    emp1 10000
    emp2 10000
    emp3 11000
    emp4 13000
    emp5 15000

    I want avg salary in a separate column like

    emp salary AvgSalary
    --- ------- -----------
    emp1 10000 11800.0000
    emp2 10000 11800.0000
    emp3 11000 11800.0000
    emp4 13000 11800.0000
    emp5 15000 11800.0000

    I am getting the result using
    Code:
    SELECT emp, salary, (SELECT AVG( salary ) FROM empl ) 'average'
    FROM empl
    How can I do it using only one select statement?

    Thanks,
    Shrawan

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,911
    You can't have grouped and non-grouped by columns in the same SELECT statement, so what you are doing is fine.

Posting Permissions

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