Gossamer Forum
Home : General : Databases and SQL :

Sql Query statment (please help!)

Quote Reply
Sql Query statment (please help!)
I just wrote the following query:

-------------------------------------------------
SELECT Salesperson.salesperson_id, Salesperson.salesperson_name,
Region.salesperson_region_commission, SUM(Line_item.product_qty_ordered) AS "Sales Order Count"

FROM Line_item, Sales_order, Salesperson, Region

WHERE Line_item.order_id = Sales_order.order_id
AND Sales_order.salesperson_id = Salesperson.salesperson_id
AND Salesperson.salesperson_region_id = Region.salesperson_region_id

GROUP BY Salesperson.salesperson_id, Salesperson.salesperson_name,
Region.salesperson_region_commission;
---------------------------------------------

My only problem is that I dont' know how to pick out the highest value from this sum so it would display only one record with the highest value.

SUM(Line_item.product_qty_ordered) AS "Sales Order Count"

Please help me out. Thanks a lot. HUY
Quote Reply
Re: [hdnguyen3] Sql Query statment (please help!) In reply to
Buy a PL/SQL book please
I don't know either

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [hdnguyen3] Sql Query statment (please help!) In reply to
MAX() picks the highest value.
Quote Reply
Re: [hdnguyen3] Sql Query statment (please help!) In reply to
Add a

ORDER BY "Sales Order Count" DESC

to order by the sales count, and then only fetch one row ("LIMIT 1").

Cheers,

Alex
--
Gossamer Threads Inc.