Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to add ORDER BY ... DESC

Status
Not open for further replies.

milton747

Programmer
Apr 21, 2005
133
US
Hi folks,
I need to add: ORDER BY TotalShipped DESC
to get rows with large numbers first. Any help welcome.I've tried vairous places and get SQL errs.

Thanks
Milton

-----------


select country,
sum(TotalShipped)as shipped,
sum(TotalCancelled) as cancelled,
sum(TotalInProcess) as inProcess,
sum(TotalDisputed) as disputed,
sum(TotalOnHold) as onHold,
sum(TotalResolved) as resolved
from (
SELECT country,
case when status = 'Cancelled'
then CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED * CLASSICMODELS.ORDERDETAILS.PRICEEACH else 0 end as TotalCancelled,
case when status = 'Shipped'
then CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED * CLASSICMODELS.ORDERDETAILS.PRICEEACH else 0 end as TotalShipped ,
case when status = 'In Process'
then CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED * CLASSICMODELS.ORDERDETAILS.PRICEEACH else 0 end as TotalInProcess,
case when status = 'Disputed'
then CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED * CLASSICMODELS.ORDERDETAILS.PRICEEACH else 0 end as TotalDisputed,
case when status = 'On Hold'
then CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED * CLASSICMODELS.ORDERDETAILS.PRICEEACH else 0 end as TotalOnHold,
case when status = 'Resolved'
then CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED * CLASSICMODELS.ORDERDETAILS.PRICEEACH else 0 end as TotalResolved

FROM CLASSICMODELS.CUSTOMERS,
CLASSICMODELS.ORDERS,
CLASSICMODELS.ORDERDETAILS
WHERE CLASSICMODELS.CUSTOMERS.CUSTOMERNUMBER = CLASSICMODELS.ORDERS.CUSTOMERNUMBER
AND CLASSICMODELS.ORDERS.ORDERNUMBER = CLASSICMODELS.ORDERDETAILS.ORDERNUMBER
) as m1

group by country
 
Like this ?
...
group by country
order by 2 desc

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top