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
  1. Home
  2. General Programming
  3. C#
  4. Any query????

Any query????

Scheduled Pinned Locked Moved C#
questiondatabasesales
5 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 below salesreport table, how can I get results of max sales of sales persons in one query? salesperson sales orderId Michele 120 120121 Guido 230 120122 Michele 300 120123 Michele 250 120124 Franco 100 120125 Guido 500 120126 Franco 400 120127 the query result must be; salesperson sales Michele 300 Guido 500 Franco 400

    G 1 Reply Last reply
    0
    • O omegazafer

      Hi friends, I have below salesreport table, how can I get results of max sales of sales persons in one query? salesperson sales orderId Michele 120 120121 Guido 230 120122 Michele 300 120123 Michele 250 120124 Franco 100 120125 Guido 500 120126 Franco 400 120127 the query result must be; salesperson sales Michele 300 Guido 500 Franco 400

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      This is more for the SQL forum methinks. Also sounds very much like homework. Anyway here is the solution (try and understand why it works rather than just copying it) select salesperson,max(sales) from salesreport group by salesperson Regards Guy

      You always pass failure on the way to success.

      modified on Friday, December 28, 2007 4:27:52 PM

      O 1 Reply Last reply
      0
      • G GuyThiebaut

        This is more for the SQL forum methinks. Also sounds very much like homework. Anyway here is the solution (try and understand why it works rather than just copying it) select salesperson,max(sales) from salesreport group by salesperson Regards Guy

        You always pass failure on the way to success.

        modified on Friday, December 28, 2007 4:27:52 PM

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

        Thanks so much. You are right. It is a homework but only a part of my homework. I made it simple to apply my question. I am getting query from northwind databasesample. According to sales person's most sold products, I am using group by also and other things. I can't where anad how to put max to below code. The below code gives, all sales of salespersons according to product. 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 order by employees.firstname As you see, I don't have any aim to copy your response. I have gotten stuck in a point and I wanted help.

        G 1 Reply Last reply
        0
        • O omegazafer

          Thanks so much. You are right. It is a homework but only a part of my homework. I made it simple to apply my question. I am getting query from northwind databasesample. According to sales person's most sold products, I am using group by also and other things. I can't where anad how to put max to below code. The below code gives, all sales of salespersons according to product. 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 order by employees.firstname As you see, I don't have any aim to copy your response. I have gotten stuck in a point and I wanted help.

          G Offline
          G Offline
          GuyThiebaut
          wrote on last edited by
          #4

          omegazafer wrote:

          You are right. It is a homework but only a part of my homework.

          I appreciate your honesty in this. With regards to the query - it's not the simplest of queries you have written - a suggestion: break it into it's component parts and get those parts working first.

          omegazafer wrote:

          ((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

          looks overly complex to me(does it work?). Regards Guy

          You always pass failure on the way to success.
          O 1 Reply Last reply
          0
          • G GuyThiebaut

            omegazafer wrote:

            You are right. It is a homework but only a part of my homework.

            I appreciate your honesty in this. With regards to the query - it's not the simplest of queries you have written - a suggestion: break it into it's component parts and get those parts working first.

            omegazafer wrote:

            ((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

            looks overly complex to me(does it work?). Regards Guy

            You always pass failure on the way to success.
            O Offline
            O Offline
            omegazafer
            wrote on last edited by
            #5

            Thans so much, your first response helped me so much because I didn't know the using of max with group by. You can be sure, that code is working :) also it is the response of one question of my homework. Now, i am dealing the other question I asked you. Regards Good Days

            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