Soldato
- Joined
- 26 Aug 2005
- Posts
- 6,901
- Location
- London
I want to basically find out if the count of something is more than 3, then apply a discount. I am creating a view.
Can anyone help?
Can anyone help?
select customer.CUSTOMER, customer.customer_contact, customer.CUSTOMER_ID, order_item.order_number, sum((belt_design.PRICE * order_specification.order_quantity)) as Total_Price_Of_Orders, COUNT(1)
INTO TmpTableName
from customer, order_item, belt_design, order_specification
where customer.CUSTOMER_ID = order_item.CUSTOMER_ID
AND ORDER_ITEM.ORDER_NUMBER = order_specification.ORDER_NUMBER
and order_specification.DESIGN_NUMBER = belt_design.DESIGN_NUMBER
group by customer.CUSTOMER, customer.customer_contact, customer.CUSTOMER_ID, order_item.order_number
HAVING COUNT(1)>3
order by customer.customer;
UPDATE TableNameWithPriceFieldIn
FROM TmpTableName tmp
SET TableNameWithPriceFieldIn.Price = (TableNameWithPriceFieldIn.Price*0.80)
WHERE TableNameWithPriceFieldIn.customer_id = tmp.customer_id
AND TableNameWithPriceFieldIn.order_number = tmp.order_number