Invantive Control 中针对 Excel 的相同精确在线查询在与客户一起执行时给出不同的结果
Same Exact Online query in Invantive Control for Excel gives different result when executed with customer
我有以下查询以根据来自 Exact Online 的区域组生成收入报告:
select itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
, sum(quantity)
aantal
, sum(amountdc)
omzet
, sum(quantity2jaar)
aantal2014
, sum(omzet2jaar)
omzet2014
, sum(quantity1jaar)
aantal2015
, sum(omzet1jaar)
omzet2015
, sum(quantityhuidigejaar)
aantal2016
, sum(omzethuidigejaar)
omzet2016
from ( select substr(act.postcode, 1, 2)
, case
when financialyear = year(getdate()) - 0
then amountdc
else 0
end
* -1
omzethuidigejaar
, case
when financialyear = year(getdate()) - 1
then amountdc
else 0
end
* -1
omzet1jaar
, case
when financialyear = year(getdate()) - 2
then amountdc
else 0
end
* -1
omzet2jaar
, case
when financialyear = year(getdate()) - 0
then quantity
else 0
end
quantityhuidigejaar
, case
when financialyear = year (getdate()) - 1
then quantity
else 0
end
quantity1jaar
, case
when financialyear = year(getdate()) - 2
then quantity
else 0
end
quantity2jaar
, case
when substr(act.postcode, 1, 2) >= '10'
and substr(act.postcode, 1, 2) < '20'
then '1000-1999'
when substr(act.postcode, 1, 2) >= '20'
and substr(act.postcode, 1, 2) < '30'
then '2000-2999'
when substr(act.postcode, 1, 2) >= '30'
and substr(act.postcode, 1, 2) < '40'
then '3000-3999'
when substr(act.postcode, 1, 2) >= '40'
and substr(act.postcode, 1, 2) < '50'
then '4000-4999'
when substr(act.postcode, 1, 2) >= '50'
and substr(act.postcode, 1, 2) < '60'
then '5000-5999'
when substr(act.postcode, 1, 2) >= '60'
and substr(act.postcode, 1, 2) < '70'
then '6000-6999'
when substr(act.postcode, 1, 2) >= '70'
and substr(act.postcode, 1, 2) < '80'
then '7000-7999'
when substr(act.postcode, 1, 2) >= '80'
and substr(act.postcode, 1, 2) <= '89'
then '8000-8999'
when substr(act.postcode, 1, 2) >= '90'
and substr(act.postcode, 1, 2) <= '99'
then '9000-9999'
else 'unknown'
end
postcodegebied
, -1 * tle.amountdc
, tle.financialperiod
, tle.financialyear
, act.country
, act.name
, itm.code
, itm.description
, tle.quantity
, itm.itemgroupdescription
, itm.itemgroupcode
from transactionlines tle
join exactonlinerest.crm.accounts act
on act.code = tle.accountcode
join exactonlinerest.financial.glaccounts glt
on glt.code = tle.glaccountcode
--
-- Type 110: grootboekrekening van het type omzet
--
and glt.type = 110
join exactonlinerest.logistics.items itm
on tle.itemcode = itm.code
--
-- zodat er alleen transacties worden meegenomen die op een artikel geboekt zijn.
--
where tle.itemcode is not null
) tle2
group
by itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
order
by itemgroupcode
, financialyear
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialperiod
在客户的机器上执行此查询时,我希望得到相同的结果。但结果不同。根据查询是 运行 as Exact Online user 'ME@acme.com' 还是 'OTHERPERSON@acme.com'.
,每个金额和数量乘以因子 8
这是怎么发生的,我该如何解决?
您的查询缺少一些优化并且不包括完整的连接条件。
请注意,例如一个项目的唯一自然键或业务键既是部门(公司)又是项目代码,因此始终将两者都包含在联接中。当您忘记在适用的地方包括除法时,如果您使用相同的(副本)除法,您会乘以行数。对于非副本,您会得到不同的结果。
考虑到你得到的是 8 倍并且存在 3 个连接,我猜你 运行 有时在 Exact Online 中选择了 2 identical/copy 个分区,这会导致功率(2、3 ) = 高值的 8 倍。
此外,您正在检索许多未在汇总中使用的总帐交易行,例如 3 年或更早的交易行。最好用 financialyear >= ...
.
这样的子句排除那些早期的人
正确的查询应该是这样的:
select itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
, sum(quantity)
aantal
, sum(amountdc)
omzet
, sum(quantity2jaar)
aantal2014
, sum(omzet2jaar)
omzet2014
, sum(quantity1jaar)
aantal2015
, sum(omzet1jaar)
omzet2015
, sum(quantityhuidigejaar)
aantal2016
, sum(omzethuidigejaar)
omzet2016
from ( select substr(act.postcode, 1, 2)
, case
when financialyear = year(getdate()) - 0
then amountdc
else 0
end
* -1
omzethuidigejaar
, case
when financialyear = year(getdate()) - 1
then amountdc
else 0
end
* -1
omzet1jaar
, case
when financialyear = year(getdate()) - 2
then amountdc
else 0
end
* -1
omzet2jaar
, case
when tle.financialyear = year(getdate()) - 0
then tle.quantity
else 0
end
quantityhuidigejaar
, case
when tle.financialyear = year (getdate()) - 1
then tle.quantity
else 0
end
quantity1jaar
, case
when tle.financialyear = year(getdate()) - 2
then tle.quantity
else 0
end
quantity2jaar
, case
when substr(act.postcode, 1, 2) >= '10'
and substr(act.postcode, 1, 2) < '20'
then '1000-1999'
when substr(act.postcode, 1, 2) >= '20'
and substr(act.postcode, 1, 2) < '30'
then '2000-2999'
when substr(act.postcode, 1, 2) >= '30'
and substr(act.postcode, 1, 2) < '40'
then '3000-3999'
when substr(act.postcode, 1, 2) >= '40'
and substr(act.postcode, 1, 2) < '50'
then '4000-4999'
when substr(act.postcode, 1, 2) >= '50'
and substr(act.postcode, 1, 2) < '60'
then '5000-5999'
when substr(act.postcode, 1, 2) >= '60'
and substr(act.postcode, 1, 2) < '70'
then '6000-6999'
when substr(act.postcode, 1, 2) >= '70'
and substr(act.postcode, 1, 2) < '80'
then '7000-7999'
when substr(act.postcode, 1, 2) >= '80'
and substr(act.postcode, 1, 2) <= '89'
then '8000-8999'
when substr(act.postcode, 1, 2) >= '90'
and substr(act.postcode, 1, 2) <= '99'
then '9000-9999'
else 'unknown'
end
postcodegebied
, -1 * tle.amountdc
, tle.financialperiod
, tle.financialyear
, act.country
, act.name
, itm.code
, itm.description
, tle.quantity
, itm.itemgroupdescription
, itm.itemgroupcode
from transactionlines tle
join exactonlinerest..accounts act
on act.code = tle.accountcode
and act.division = tle.division
join exactonlinerest..glaccounts glt
on glt.code = tle.glaccountcode
--
-- Type 110: GL Account of type Revenue.
--
and glt.type = 110
and glt.division = tle.division
join exactonlinerest.logistics.items itm
on itm.code = tle.itemcode
and itm.division = tle.division
--
-- Only transaction lines with an item.
--
where tle.itemcode is not null
--
-- Only journal for revenues.
--
and tle.journalcode = '70'
--
-- Optimization: not interested in older transactions than 2 years.
--
and tle.financialyear >= year(getdate()) - 2
) tle2
group
by itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
order
by itemgroupcode
, financialyear
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialperiod
我有以下查询以根据来自 Exact Online 的区域组生成收入报告:
select itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
, sum(quantity)
aantal
, sum(amountdc)
omzet
, sum(quantity2jaar)
aantal2014
, sum(omzet2jaar)
omzet2014
, sum(quantity1jaar)
aantal2015
, sum(omzet1jaar)
omzet2015
, sum(quantityhuidigejaar)
aantal2016
, sum(omzethuidigejaar)
omzet2016
from ( select substr(act.postcode, 1, 2)
, case
when financialyear = year(getdate()) - 0
then amountdc
else 0
end
* -1
omzethuidigejaar
, case
when financialyear = year(getdate()) - 1
then amountdc
else 0
end
* -1
omzet1jaar
, case
when financialyear = year(getdate()) - 2
then amountdc
else 0
end
* -1
omzet2jaar
, case
when financialyear = year(getdate()) - 0
then quantity
else 0
end
quantityhuidigejaar
, case
when financialyear = year (getdate()) - 1
then quantity
else 0
end
quantity1jaar
, case
when financialyear = year(getdate()) - 2
then quantity
else 0
end
quantity2jaar
, case
when substr(act.postcode, 1, 2) >= '10'
and substr(act.postcode, 1, 2) < '20'
then '1000-1999'
when substr(act.postcode, 1, 2) >= '20'
and substr(act.postcode, 1, 2) < '30'
then '2000-2999'
when substr(act.postcode, 1, 2) >= '30'
and substr(act.postcode, 1, 2) < '40'
then '3000-3999'
when substr(act.postcode, 1, 2) >= '40'
and substr(act.postcode, 1, 2) < '50'
then '4000-4999'
when substr(act.postcode, 1, 2) >= '50'
and substr(act.postcode, 1, 2) < '60'
then '5000-5999'
when substr(act.postcode, 1, 2) >= '60'
and substr(act.postcode, 1, 2) < '70'
then '6000-6999'
when substr(act.postcode, 1, 2) >= '70'
and substr(act.postcode, 1, 2) < '80'
then '7000-7999'
when substr(act.postcode, 1, 2) >= '80'
and substr(act.postcode, 1, 2) <= '89'
then '8000-8999'
when substr(act.postcode, 1, 2) >= '90'
and substr(act.postcode, 1, 2) <= '99'
then '9000-9999'
else 'unknown'
end
postcodegebied
, -1 * tle.amountdc
, tle.financialperiod
, tle.financialyear
, act.country
, act.name
, itm.code
, itm.description
, tle.quantity
, itm.itemgroupdescription
, itm.itemgroupcode
from transactionlines tle
join exactonlinerest.crm.accounts act
on act.code = tle.accountcode
join exactonlinerest.financial.glaccounts glt
on glt.code = tle.glaccountcode
--
-- Type 110: grootboekrekening van het type omzet
--
and glt.type = 110
join exactonlinerest.logistics.items itm
on tle.itemcode = itm.code
--
-- zodat er alleen transacties worden meegenomen die op een artikel geboekt zijn.
--
where tle.itemcode is not null
) tle2
group
by itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
order
by itemgroupcode
, financialyear
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialperiod
在客户的机器上执行此查询时,我希望得到相同的结果。但结果不同。根据查询是 运行 as Exact Online user 'ME@acme.com' 还是 'OTHERPERSON@acme.com'.
,每个金额和数量乘以因子 8这是怎么发生的,我该如何解决?
您的查询缺少一些优化并且不包括完整的连接条件。
请注意,例如一个项目的唯一自然键或业务键既是部门(公司)又是项目代码,因此始终将两者都包含在联接中。当您忘记在适用的地方包括除法时,如果您使用相同的(副本)除法,您会乘以行数。对于非副本,您会得到不同的结果。
考虑到你得到的是 8 倍并且存在 3 个连接,我猜你 运行 有时在 Exact Online 中选择了 2 identical/copy 个分区,这会导致功率(2、3 ) = 高值的 8 倍。
此外,您正在检索许多未在汇总中使用的总帐交易行,例如 3 年或更早的交易行。最好用 financialyear >= ...
.
正确的查询应该是这样的:
select itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
, sum(quantity)
aantal
, sum(amountdc)
omzet
, sum(quantity2jaar)
aantal2014
, sum(omzet2jaar)
omzet2014
, sum(quantity1jaar)
aantal2015
, sum(omzet1jaar)
omzet2015
, sum(quantityhuidigejaar)
aantal2016
, sum(omzethuidigejaar)
omzet2016
from ( select substr(act.postcode, 1, 2)
, case
when financialyear = year(getdate()) - 0
then amountdc
else 0
end
* -1
omzethuidigejaar
, case
when financialyear = year(getdate()) - 1
then amountdc
else 0
end
* -1
omzet1jaar
, case
when financialyear = year(getdate()) - 2
then amountdc
else 0
end
* -1
omzet2jaar
, case
when tle.financialyear = year(getdate()) - 0
then tle.quantity
else 0
end
quantityhuidigejaar
, case
when tle.financialyear = year (getdate()) - 1
then tle.quantity
else 0
end
quantity1jaar
, case
when tle.financialyear = year(getdate()) - 2
then tle.quantity
else 0
end
quantity2jaar
, case
when substr(act.postcode, 1, 2) >= '10'
and substr(act.postcode, 1, 2) < '20'
then '1000-1999'
when substr(act.postcode, 1, 2) >= '20'
and substr(act.postcode, 1, 2) < '30'
then '2000-2999'
when substr(act.postcode, 1, 2) >= '30'
and substr(act.postcode, 1, 2) < '40'
then '3000-3999'
when substr(act.postcode, 1, 2) >= '40'
and substr(act.postcode, 1, 2) < '50'
then '4000-4999'
when substr(act.postcode, 1, 2) >= '50'
and substr(act.postcode, 1, 2) < '60'
then '5000-5999'
when substr(act.postcode, 1, 2) >= '60'
and substr(act.postcode, 1, 2) < '70'
then '6000-6999'
when substr(act.postcode, 1, 2) >= '70'
and substr(act.postcode, 1, 2) < '80'
then '7000-7999'
when substr(act.postcode, 1, 2) >= '80'
and substr(act.postcode, 1, 2) <= '89'
then '8000-8999'
when substr(act.postcode, 1, 2) >= '90'
and substr(act.postcode, 1, 2) <= '99'
then '9000-9999'
else 'unknown'
end
postcodegebied
, -1 * tle.amountdc
, tle.financialperiod
, tle.financialyear
, act.country
, act.name
, itm.code
, itm.description
, tle.quantity
, itm.itemgroupdescription
, itm.itemgroupcode
from transactionlines tle
join exactonlinerest..accounts act
on act.code = tle.accountcode
and act.division = tle.division
join exactonlinerest..glaccounts glt
on glt.code = tle.glaccountcode
--
-- Type 110: GL Account of type Revenue.
--
and glt.type = 110
and glt.division = tle.division
join exactonlinerest.logistics.items itm
on itm.code = tle.itemcode
and itm.division = tle.division
--
-- Only transaction lines with an item.
--
where tle.itemcode is not null
--
-- Only journal for revenues.
--
and tle.journalcode = '70'
--
-- Optimization: not interested in older transactions than 2 years.
--
and tle.financialyear >= year(getdate()) - 2
) tle2
group
by itemgroupcode
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialyear
, financialperiod
order
by itemgroupcode
, financialyear
, itemgroupdescription
, code
, description
, country
, postcodegebied
, name
, financialperiod