0

我需要tblgl (tblgl.SUM(InMonthActual))汇总满足以下条件的选定成本中心 (tblgl.CostCentreCode) 的交易:

  1. tblgl.PeriodNumber = 2
  2. tblgl.CostCentreCode = tblcostcentrehierarchy.CostCentreCode WHERE tblcostcentrehierarchy.Level7 = "RWK312 CORPORATE"
  3. tblgl.CostCentreCode = tblcostcentreallocations.CostCentreCode WHERE tblcostcentreallocations.Username = "jonest"

目前我正在运行 3 个单独的查询来创建一个用于下一个查询的数组。

有没有办法做到这一点(也许使用JOIN)?

4

2 回答 2

1

我希望这个查询能获取你想要的数据。检查并让我知道它是否适合您。

   SELECT SUM(tb1.`InMonthActual`) 
   FROM `tblgl` as tb1 
   JOIN `tblcostcentrehierarchy` as tb2 ON tb1.`CostCetntreCode` = tb2.`CostCentreCode`
   JOIN `tblcostcentreallocations` as tb3 ON tb1.`CostCetntreCode` = tb3.`CostCentreCode`
   WHERE tb1.`PeriodNumber` = '2' AND tb2.`Level17` = "RWK312 CORPORATE" AND tb3.`Username` = "jonest"
于 2013-07-07T13:56:09.047 回答
0

试试看

SELECT SUM(tblgl.InMonthActual) FROM tblgl
INNER JOIN tblcostcentrehierarchy ON (tblgl.CostCentreCode = tblcostcentrehierarchy.CostCentreCode AND tblgl.PeriodNumber = 2)
INNER JOIN tblcostcentreallocations ON  (tblgl.CostCentreCode = tblcostcentreallocations.CostCentreCode)
WHERE tblcostcentreallocations.Username = "jonest" AND tblcostcentrehierarchy.Level7 = "RWK312 CORPORATE"
GROUP BY tblgl.InMonthActual

希望它工作正常

于 2013-07-07T13:53:06.893 回答