Any query????
-
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
-
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
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 GuyYou always pass failure on the way to success.
modified on Friday, December 28, 2007 4:27:52 PM
-
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 GuyYou always pass failure on the way to success.
modified on Friday, December 28, 2007 4:27:52 PM
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.
-
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.
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.
-
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.
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