我想执行一个查询,该查询在动态提供的值数组上运行,并且这些值不存在于表中。
我尝试在ANY运算符中传递静态值,但这似乎不起作用
select
models.sku,
(sum(models.unitretailprice) *
sum(coefficients.unit_retail_price)) +
(sum(models.flag::int) * sum(coefficients.flag::int)) +
(sum(models.sku_moving_avg) * sum(coefficients.sku_moving_avg)) +
(sum(models.sku_week_avg) * sum(coefficients.sku_week_avg)) +
(sum(models.sku_week_normal)* sum(coefficients.sku_week_normal)) as baseline,
(sum(models.testing) * sum(coefficients.f)) +
(5 * sum(coefficients.p)) +
(0 * sum(coefficients.a)) as promoIncremental,
(sum(models.basket_dollar_off) * sum(coefficients.basket_dollar_off)) +
(sum(models.category_per_off) * sum(coefficients.category_per_off)) +
(sum(models.disc_per) * sum(coefficients.disc_per)) as couponIncremnetal
from
models join coefficients
on
models.sku = coefficients.sku
and
models.si_type = coefficients.si_type
and
models.model_type = coefficients.model_type
where
coefficients.sku in ('12841276', '11873916') and coefficients.shop_descr = 'Papercrafting Technology'
group by models.sku
在这里,我希望 sum(models.testing)接受并运行诸如0、5、10、20、25之类的值,以便每次迭代获得多个行。
>预期查询将运行:::
select
models.sku,
(sum(models.unitretailprice) *
sum(coefficients.unit_retail_price)) +
(sum(models.flag::int) * sum(coefficients.flag::int)) +
(sum(models.sku_moving_avg) * sum(coefficients.sku_moving_avg)) +
(sum(models.sku_week_avg) * sum(coefficients.sku_week_avg)) +
(sum(models.sku_week_normal)* sum(coefficients.sku_week_normal)) as baseline,
(5 * sum(coefficients.f)) +
(5 * sum(coefficients.p)) +
(0 * sum(coefficients.a)) as promoIncremental,
(sum(models.basket_dollar_off) * sum(coefficients.basket_dollar_off)) +
(sum(models.category_per_off) * sum(coefficients.category_per_off)) +
(sum(models.disc_per) * sum(coefficients.disc_per)) as couponIncremnetal
from
models join coefficients
on
models.sku = coefficients.sku
and
models.si_type = coefficients.si_type
and
models.model_type = coefficients.model_type
where
coefficients.sku in ('12841276', '11873916') and coefficients.shop_descr = 'Papercrafting Technology'
group by models.sku
然后是10
select
models.sku,
(sum(models.unitretailprice) *
sum(coefficients.unit_retail_price)) +
(sum(models.flag::int) * sum(coefficients.flag::int)) +
(sum(models.sku_moving_avg) * sum(coefficients.sku_moving_avg)) +
(sum(models.sku_week_avg) * sum(coefficients.sku_week_avg)) +
(sum(models.sku_week_normal)* sum(coefficients.sku_week_normal)) as baseline,
(10 * sum(coefficients.f)) +
(5 * sum(coefficients.p)) +
(0 * sum(coefficients.a)) as promoIncremental,
(sum(models.basket_dollar_off) * sum(coefficients.basket_dollar_off)) +
(sum(models.category_per_off) * sum(coefficients.category_per_off)) +
(sum(models.disc_per) * sum(coefficients.disc_per)) as couponIncremnetal
from
models join coefficients
on
models.sku = coefficients.sku
and
models.si_type = coefficients.si_type
and
models.model_type = coefficients.model_type
where
coefficients.sku in ('12841276', '11873916') and coefficients.shop_descr = 'Papercrafting Technology'
group by models.sku
然后是15
select
models.sku,
(sum(models.unitretailprice) *
sum(coefficients.unit_retail_price)) +
(sum(models.flag::int) * sum(coefficients.flag::int)) +
(sum(models.sku_moving_avg) * sum(coefficients.sku_moving_avg)) +
(sum(models.sku_week_avg) * sum(coefficients.sku_week_avg)) +
(sum(models.sku_week_normal)* sum(coefficients.sku_week_normal)) as baseline,
(15 * sum(coefficients.f)) +
(5 * sum(coefficients.p)) +
(0 * sum(coefficients.a)) as promoIncremental,
(sum(models.basket_dollar_off) * sum(coefficients.basket_dollar_off)) +
(sum(models.category_per_off) * sum(coefficients.category_per_off)) +
(sum(models.disc_per) * sum(coefficients.disc_per)) as couponIncremnetal
from
models join coefficients
on
models.sku = coefficients.sku
and
models.si_type = coefficients.si_type
and
models.model_type = coefficients.model_type
where
coefficients.sku in ('12841276', '11873916') and coefficients.shop_descr = 'Papercrafting Technology'
group by models.sku