Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi , I want to get all order id numbers for selected customer which not payed till now, my data show as following:

http://i.stack.imgur.com/HaexV.jpg[^]

SQL
What I want is Write a SELECT statement that answers this question:

select orderID from order where customer id = @custID and Total cashmovementValue for current order id is less than total (sold quantity * salePrice ) for current order id.

How to do it?

Thanks.
Posted

1 solution

Select o.OrderId 
 from dbo.Order 
  inner join dbo.Cashmovement cm 
   on o.OrderId = cm.OrderId 
    inner join dbo.Orderdetails od 
     on od.OrderId = o.OrderId 
      inner join dbo.Product p 
       on p.Productid = od.ProductId 
        where o.CustomerId = @Customerid 
   Group by o.OrderId
    Having Sum(cm.Cashmovement) < (od.SoldQuantity * p.SalePrice)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900