This should work
Code:
select dbo.Products.ProductName,
SUM (dbo.[order details].unitprice * dbo.[order details].Quantity) as Amount
from dbo.[Order Details]
inner join dbo.Orders on
dbo.[Order Details].OrderID = dbo.Orders.OrderID
inner join dbo.Products on
dbo.[Order Details].ProductID = dbo.Products.ProductID
where dbo.orders.orderdate between '1997-01-01 00:00:00.000' and '1997-12-31 00:00:00.000'
group by dbo.Products.ProductName
HAVING SUM (dbo.[order details].unitprice * dbo.[order details].Quantity) >= 15000.00
order by dbo.Products.ProductName desc
The HAVING clause works on the aggerated data of the GROUP BY.
Also handy when you want to select on groups, based on the amount of records:
Find all duplicates in a table:
SELECT ....
FROM...
WHERE...
GROUP BY aUniqueColumn
HAVING COUNT(*) > 1
Select the smallest football teams
SELECT FootballTeam.Name, COUNT(*) as NbrOfMembers
FROM ...
WHERE...
GROUP BY FootballTeamName
HAVING COUNT(*) < 100