如何从 SQL Server 2000 的表中提取当前库存
我正在使用 Visual Studio 2005 和 SQL Server 2000 在 vb.net 中进行制作和应用。我必须跟踪库存。添加后,库存的状态设置为“未售出”。当某些库存被移除时,交易会将库存状态保持为“已售出”。对于已过期的股票,状态也可以是“已过期”,当向公司认领过期股票时,状态为“已认领”...现在,我想从这一切中提取当前手中的股票。在基本级别上,有两个状态值,即“已售出”和“未售出”,我使用以下查询从数据库中提取结果,但它不会计算已售出和未售出商品的差异...
select category, item_name,
sum(crtns_added) as Cartons, sum(pieces_added) as Pieces,
sum(total_price)
from Stock
where status = 'unsold'
group by category, item_name
我也尝试过这个
select category, item_name, (sum(crtns_added) - sum(crtns_removed)) as Cartons,
(sum(pieces_added)- sum(pieces_removed)) as Pieces,
sum(total_price)
from Stock
where status = 'unsold' or status = 'sold'
group by category, item_name
I'm making and application in vb.net using Visual Studio 2005 and SQL Server 2000. I have to keep track of the stock. The stock when added has its status set as "Unsold". When some stock is removed then the transaction keeps the status of stock as "Sold". The status can also be "Expired" for the stock that has been expired and when expired stock is claimed to the company then the status is "claimed"...Now from all this I want to extract the stock which is currently in hand. At a basic level with two status values i.e. "Sold" and "Unsold" I'm using the following query to extract the results from database but it doesn't calculate the difference sold and unsold items...
select category, item_name,
sum(crtns_added) as Cartons, sum(pieces_added) as Pieces,
sum(total_price)
from Stock
where status = 'unsold'
group by category, item_name
I have also tried this
select category, item_name, (sum(crtns_added) - sum(crtns_removed)) as Cartons,
(sum(pieces_added)- sum(pieces_removed)) as Pieces,
sum(total_price)
from Stock
where status = 'unsold' or status = 'sold'
group by category, item_name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用两个子选择来选择具有适当值的项目 - 类似于:
假设有一个
itemId
列唯一标识您的项目 - 某种主键。通过这种技术,您可以获得已售出或未售出的纸箱或件的总和 - 无论您需要什么。You need to use two sub-selects to select the items with the appropriate values - something like:
This assume there's an
itemId
column that uniquely identifies your items - some kind of a primary key. With this technique, you can get the sum of the sold or unsold cartons or pieces - whatever you need.