我正在VB.net中编写一个简单的应用程序,我陷入了一个SQL语句。让我们说我有以下表格和一些样本数据
产品表包含$link = mysqli_connect("localhost", "root", " ", "firstwebsitedb");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
if (mysqli_query($link,$sql)){
echo "<script>alert('Post is Published')</script>";
}
else{
echo "<script>alert('Post is not Published')</script>";
}
,attributes
ProductID
,ProductName
,CategoryID
,UnitPrice
QuantityOnhand
。我想跟踪我拥有的物品数量的增加和减少。这些是使产品的QuantityOnhand增加或减少的一些交易。
带有属性ProductId Name UnitPrice QTYonaHand
001 XYZ 3 25
,BillNo
,Productid
,Qty
的BillDetails表 - 表示从供应商处购买并会增加数量
Price
带有属性 BillNo ProductId Qty Price
01 001 36 3
,InvoiceId
,Productid
,Qty
的InvoiceDetails表代表对客户的销售,并会减少数量。
Price
我的目标是编写一个返回表
的SQL语句产品详情
对于示例产品XYZ
InvoiceNo ProductId Qty Price
10 001 6 4
12 001 5 4.5
提前致谢!
答案 0 :(得分:0)
这已经完成了罢工
Select BILLDATE AS DATE, 'BILL' as Type, B.BILLno as Ref, BD.QTY as QTY from Bill B
inner join BILLDETAILS BD
on
B.BILLno = BD.[BILLno]
where BD.ProductId = 001
UNION ALL
Select [Invoice Date] AS DATE , 'Invoice' as Type, S.[invoice no] as Ref, D.QTY * -1 as QTY from SALESINVOICE S
inner join SalesInvoiceDetails D
on
S.[Invoice No] = D.[Invoice NO]
where d.ProductId = 001
ORDER BY DATE ASC
但我如何添加运行余额计算列