本文介绍了如何获取SQL Server 2008中未支付的所有订单ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得所选客户的所有订单ID号码,直到现在还没付款,我的数据显示如下:
[]
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[^]
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.
推荐答案
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)
这篇关于如何获取SQL Server 2008中未支付的所有订单ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!