SQLUSA

Microsoft SQL Server 2000 Best Practices

How to find all orders with 10% discount?

 

Execute the following script in Query Analyzer to get a report on all orders with 10% (0.1) discount:

use Northwind

select o.OrderID, SeqNo, ProductName, o.UnitPrice, o.Quantity,
Amount=o.UnitPrice*o.Quantity, Discount=convert(decimal(3,2), Discount)
from Products p
join [Order Details] o on p.ProductID=o.ProductID
join
(select count(*) as SeqNo,
a.OrderID, a.ProductID
from [Order Details] a join
[Order Details] b
on a.ProductID >= b.ProductID
and a.OrderID = b.OrderID
group by a.OrderID, a.ProductID) seq
on o.OrderID= seq.OrderID and
o.ProductID = seq.ProductID
where o.Discount=0.1
order by o.OrderID

 

 

The World Leader in SQL Server Training
 
SQLUSA.com Home Page