Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Any query about northwind? [modified]

Any query about northwind? [modified]

Scheduled Pinned Locked Moved C#
databasehelpsalestoolsquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    omegazafer
    wrote on last edited by
    #1

    Hi friends, I have a homework, i worked for days but I got stuck in a point. I can't go out of this point. I am very glad if you can help me. I make effort to get a query from from northwind database sample. I want max sales of employees according to product. There are 9 employees(sales persons). There are 77 products type. Salespersons sell this products. I want ,which product was sold maximumly according to sales turnover. The result must be like below salesperson product sales amount salesperson1 product a x salesperson2 product b y . . . . . . salesperson9 product h w. I tryed below script, I can find max sales of each salespersons but I can't add productname column to this query. select t.firstname,t.lastname,max(t.sales) as sales from (select employees.Firstname,employees.lastname,products.productname, sum("order details".unitprice*quantity*(1-discount)) as Sales from ((Employees inner join orders on employees.employeeID=orders.employeeID) inner join "order details" on orders.orderID="order details".orderID) inner join products on products.productID="order details".productID group by employees.lastname,employees.firstname,products.productname ) as t group by t.firstname,t.lastname order by t.firstname Note: I got answer from Jacob Sebastian like below, bu i didn't understand exactly that response. It works but I didn't understand, especially top1 clause. The result consists of 9 row but top1 gives one row according to I know and link between a and b is very complex. SELECT FirstName, LastName, (SELECT TOP 1 ProductName FROM (SELECT e.FirstName, e.LastName, p.ProductName, SUM(od.UnitPrice * od.Quantity*(1-Discount)) AS Sales FROM Orders oh INNER JOIN [Order Details] od ON oh.OrderID = od.OrderID INNER JOIN Products p ON p.ProductID = od.ProductID INNER JOIN Employees e ON e.EmployeeID = oh.EmployeeID GROUP BY e.FirstName, e.LastName, p.ProductName ) b WHERE a.FirstName = b.FirstName AND a.LastName = b.LastName ORDER BY Sales DESC ) AS ProductName, MAX(Sales) FROM ( SELECT e.FirstName, e.LastName, p.ProductName, SUM(od.UnitPrice * od.Quantity*(1-Discount)) AS Sales FROM Orders oh INNER JO

    P 1 Reply Last reply
    0
    • O omegazafer

      Hi friends, I have a homework, i worked for days but I got stuck in a point. I can't go out of this point. I am very glad if you can help me. I make effort to get a query from from northwind database sample. I want max sales of employees according to product. There are 9 employees(sales persons). There are 77 products type. Salespersons sell this products. I want ,which product was sold maximumly according to sales turnover. The result must be like below salesperson product sales amount salesperson1 product a x salesperson2 product b y . . . . . . salesperson9 product h w. I tryed below script, I can find max sales of each salespersons but I can't add productname column to this query. select t.firstname,t.lastname,max(t.sales) as sales from (select employees.Firstname,employees.lastname,products.productname, sum("order details".unitprice*quantity*(1-discount)) as Sales from ((Employees inner join orders on employees.employeeID=orders.employeeID) inner join "order details" on orders.orderID="order details".orderID) inner join products on products.productID="order details".productID group by employees.lastname,employees.firstname,products.productname ) as t group by t.firstname,t.lastname order by t.firstname Note: I got answer from Jacob Sebastian like below, bu i didn't understand exactly that response. It works but I didn't understand, especially top1 clause. The result consists of 9 row but top1 gives one row according to I know and link between a and b is very complex. SELECT FirstName, LastName, (SELECT TOP 1 ProductName FROM (SELECT e.FirstName, e.LastName, p.ProductName, SUM(od.UnitPrice * od.Quantity*(1-Discount)) AS Sales FROM Orders oh INNER JOIN [Order Details] od ON oh.OrderID = od.OrderID INNER JOIN Products p ON p.ProductID = od.ProductID INNER JOIN Employees e ON e.EmployeeID = oh.EmployeeID GROUP BY e.FirstName, e.LastName, p.ProductName ) b WHERE a.FirstName = b.FirstName AND a.LastName = b.LastName ORDER BY Sales DESC ) AS ProductName, MAX(Sales) FROM ( SELECT e.FirstName, e.LastName, p.ProductName, SUM(od.UnitPrice * od.Quantity*(1-Discount)) AS Sales FROM Orders oh INNER JO

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Please post this on the SQL forum, especially as you have had this answered before. It's only polite to continue this on the original thread.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      O 1 Reply Last reply
      0
      • P Pete OHanlon

        Please post this on the SQL forum, especially as you have had this answered before. It's only polite to continue this on the original thread.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        O Offline
        O Offline
        omegazafer
        wrote on last edited by
        #3

        I am sorry, but there are less people in sql form. Here, replies are faster and most of people in c# form know sql.

        P 1 Reply Last reply
        0
        • O omegazafer

          I am sorry, but there are less people in sql form. Here, replies are faster and most of people in c# form know sql.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          omegazafer wrote:

          I am sorry, but there are less people in sql form. Here, replies are faster and most of people in c# form know sql.

          That's an abuse of the forum system. How do I find an answer to a problem in future if it's not in a logical area? Why not ask a C# question in the C++ forum because the syntax is a little bit similar? There's a reason why these forums are organised the way they are, and it's not to provide a shortcut for somebody who's too lazy or incompetent to use the appropriate forum.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups