查询使用MYSQL显示正确的报告值

时间:2017-11-17 09:38:49

标签: mysql vb.net

这个网站在我的学习中基本上是在SQL中非常好用作参考,但现在我很难检索我想要显示的值以进行报告

我有4张桌子LEFT JOIN在一起

itm_invoice

 | invoiceNo | invoiceDate | invoiceTime | clientNo  
 +-----------+-------------+-------------+---------
 |    00001  |  2017-11-16 |   14:24:50  | CA001  

itm_invoice_det

 | invoiceNo | itemIndex |  price | qty   
 +-----------+-----------+--------+-----
 |    00001  |  it001    |   1.0  |  2  
 |    00001  |  it002    |  10.0  |  5  
 |    00001  |  it003    |   3.0  |  5

itm_invoice_pay

 | invoiceNo | payTypeNo | receiptTotal | amount | memo  
 +-----------+-----------+--------------+--------+-----
 |    00001  |        1  |       2      |    2   | NPI   
 |    00001  |        2  |      50      |   50   |  
 |    00001  |        3  |      15      |   15   | SSD   

ref_invoice_pay

 | payTypeNo | payTypeName   
 +-----------+------------
 |    1      | cash       
 |    2      | cheque     
 |    3      | bank       

这是我的疑问:

SELECT DATE_FORMAT(itm_invoice.invoiceDate, '%m/%d/%Y') AS 'DATE_',
itm_invoice.invoiceNo AS 'INVOICE_#',
itm_invoice.clientNo AS 'CLIENT_', 
man_item.itemName AS 'ITEM_',   
itm_invoice_det.qty AS 'QTY_', 
itm_invoice_det.price AS 'AMOUNT_', 
itm_invoice_pay.receiptTotal AS 'TOTAL_',
ref_invoice_pay.paymentTypeName AS 'TENDER_', 
itm_invoice_pay.amount AS 'AMOUNT_', 
itm_invoice_pay.memo AS 'MEMO_', 
man_user.username AS 'CASHIER_', 
ref_invoice_status.statusName AS 'STATUS_' 
FROM itm_invoice 
LEFT JOIN itm_invoice_det ON itm_invoice_det.invoiceNo = 
itm_invoice.invoiceNo 
LEFT JOIN itm_invoice_pay ON itm_invoice_pay.invoiceNo = 
itm_invoice.invoiceNo 
LEFT JOIN ref_invoice_pay ON ref_invoice_pay.paymentTypeNo = 
itm_invoice_pay.paymentTypeNo 
LEFT JOIN man_item ON man_item.itemNo = itm_invoice_det.itemIndex
LEFT JOIN man_client ON man_client.clientNo = itm_invoice.clientNo 
LEFT JOIN man_user ON man_user.EmpCode = itm_invoice.encodeBy 
LEFT JOIN ref_invoice_status ON 
ref_invoice_status.statusNo=itm_invoice.status 
WHERE (itm_invoice.invoiceDate >= '2017-11-16' AND itm_invoice.invoiceDate 
<= '2017-11-16') AND (itm_invoice.invoiceTime >= '00:00:00' AND 
itm_invoice.invoiceTime <= '23:59:59') AND 
(ref_invoice_status.statusName='Active' OR 
ref_invoice_status.statusName='Pending') 
GROUP BY itm_invoice_det.itemIndex ASC

This is the query Output

现在让我陷入困境,在报表查看器中显示正确的值。如您所见,TENDER和AMOUNT列具有相同的值,但在表itm_invoice_pay中具有不同的值。

我希望你能帮我解决这个问题。谢谢,我很抱歉发布输出图像。我只使用我的手机。

谢谢

PS:我没有使用任何存储过程。它简单的sql语法

0 个答案:

没有答案