Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:13:32+00:00 2026-05-15T18:13:32+00:00

This is a query based on the Northwind Database in MS SQL Server 2005.

  • 0

This is a query based on the Northwind Database in MS SQL Server 2005.

First I have to get the average of the UnitPrice from OrderDetails table, and group it by ProductID for that particular column alone and alias it as AveragePrice.

Then I need to find the maximum(AveragePrice) which is nothing but the max of previous column, how can I do it??? This is a kind of very tricky for me its taking me ages to think on it.

select
O.CustomerID,
E.EmployeeID,
E.FirstName+space(1)+E.LastName FullName,
OD.OrderID,
OD.ProductID,

(select avg(DO.UnitPrice) from OrderDetails 
    DO where OD.ProductID = DO.ProductID 
    group by DO.ProductID) AveragePrice ,

from OrderDetails OD
join Orders O
on OD.OrderID = O.OrderID

join Customers C
on C.CustomerID = O.CustomerID

join Employees E
on E.EmployeeID = O.EmployeeID

This is not a Homework question, am learning SQL, but am really stuck at this point, please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:13:33+00:00Added an answer on May 15, 2026 at 6:13 pm

    It’s 2 steps: “the ungrouped maximum of the grouped averages”

    You can expand this as needed which shows how to apply an aggregate on top of an aggregate

    SELECT
        MAX(AveragePrice) AS MaxAveragePrice
    FROM
        (
        select
             avg(UnitPrice) AS AveragePrice, ProductID
        from
            OrderDetails
        group by
            ProductID
        ) foo
    

    Or with CTE

    ;WITH AvgStuff AS
    (
        select
             avg(UnitPrice) AS AveragePrice
        from
            OrderDetails
        group by
            ProductID
    )
    SELECT
        MAX(AveragePrice) AS MaxAveragePrice
    FROM
        AvgStuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL query, and directly under it, another query based on the
I have this query to display records based on date Select * From orders
I have this update query: UPDATE aggregate_usage_input t JOIN (SELECT t2.id FROM aggregate_usage_input t2
I currently have this query: select customers.emailaddress, MAX(orders.orderdate) as last order from orders join
I'm looking at the slow query log from a drupal-based webapp, and have lines
I ma struggling with this mathematical-based query. I have the difference in seconds between
This is the same question as: How to dynamically generate SQL query based on
I have a report in SSRS 2005 that's based on a query that's similar
I have this query: SELECT * FROM table WHERE key LIKE '1,2,3,%' OR key
I have a database query based on user input, However if the user inputs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.