我正在工作ob关于我在本报告中想要的收银员的报告知道特定日期的收银员总数,我写了SQL语句,但是这句话返回重复行..当我与表进行左连接时,重复记录。这是我的SQL语句:
select DISTINCT
tblcashiers.CashierName,
IFNULL(tblcashieropeningbalance.Mount, 0) as COB,
IFNULL(tblcashdeposit.Mount, 0) as CD,
IFNULL(tblbankcashiertransfer.Mount, 0) as BCT,
IFNULL(tblsupplierrefund.Refund, 0) as SPR ,
IFNULL(tblcustomrefund.Refund , 0) as CUR,
IFNULL(tblcashpayments.Mount, 0) as CP,
IFNULL(tblcashiertransfer.Mount, 0) as CT,
IFNULL(tblcashiertransfer.Mount, 0) as CT2,
IFNULL(tblcustomerrefund.Refund, 0) as CR,
IFNULL(tblcashierbanktransfer.Mount, 0)as CBT,
IFNULL(tblexpenses.Mount, 0)as EX,
IFNULL(tblcustomespayment.Mount, 0)as CUSP
from tblcashiers
LEFT JOIN tblcashdeposit on tblcashiers.CashierID = tblcashdeposit.CashierID
LEFT JOIN tblbankcashiertransfer on tblcashiers.CashierID = tblbankcashiertransfer.CashierID
LEFT JOIN tblsupplierrefund on tblcashiers.CashierID = tblsupplierrefund.CashierID
LEFT JOIN tblcustomrefund on tblcashiers.CashierID = tblcustomrefund.CashierID
LEFT JOIN tblcashpayments on tblcashiers.CashierID = tblcashpayments.CashierID
LEFT JOIN tblcustomerrefund on tblcashiers.CashierID = tblcustomerrefund.CashierID ='2'
LEFT JOIN tblcashierbanktransfer on tblcashiers.CashierID = tblcashierbanktransfer.CashierID
LEFT JOIN tblcashiertransfer on tblcashiers.CashierID = tblcashiertransfer.FromCashierID
LEFT JOIN tblcashiertransfer as tblcashiertransfer2 on tblcashiers.CashierID = tblcashiertransfer2.ToCashierID
-- LEFT JOIN tblcashiers as tblcashiers on tblcashiers.CashierID = tblcashiers.CashierID
LEFT JOIN tblcashieropeningbalance on tblcashieropeningbalance.CashierID = tblcashiers.CashierID
LEFT JOIN tblexpenses as tblexpenses on tblcashiers.CashierID = tblexpenses.CashierID
LEFT JOIN tblcustomespayment as tblcustomespayment on tblcashiers.CashierID = tblcustomespayment.CashierID
where tblcashiers.CashierID = 2
and tblcashdeposit .TransDate >= '2016-01-01'
and tblcashdeposit .TransDate <= '2016-03-01'
GROUP BY tblcashieropeningbalance.TransDate,
tblcashdeposit.TransDate, tblbankcashiertransfer.TransDate,
tblsupplierrefund.RefundDate, tblcashpayments.TransDate,
tblcustomerrefund.RefundDate, tblcashierbanktransfer.TransDate,
tblcashiertransfer.TransDate, tblcashiertransfer.TransDate,
tblexpenses.TransDate,tblcustomespayment.TransDate
如何解决此问题?
答案 0 :(得分:-1)
从查询中删除GROUP BY。 GROUP BY仅在SELECT中使用聚合函数混合普通列时使用。您的查询不包含任何聚合函数(min,max ...),因此您不需要GROUP BY。