我需要查询仅显示计数(sku)> 10

问题描述 投票:0回答:1

如何将我已要求汇总的列中的总数相加?

select 
--distinct  batch_date, bol_nbr, cur_opr, lane_nbr, size_code, sku 
loc_code, ship_lab, size_code, sku, COUNT(SKU)
from sherwin.prdinv
where sku IN ('B28W8030', 'B20W12651', 'A87W1351', 'B31W4651', 'A6W151') and (loc_code like 'H0%' or (loc_code like 'B%' ))
and REGEXP_LIKE((SUBSTR(loc_code,3)), '^[[:digit:]]+$')
group by loc_code, ship_lab, SKU, size_code
ORDER BY Loc_code asc;

我试过:

where sku IN ('B28W8030', 'B20W12651', 'A87W1351', 'B31W4651', 'A6W151') and (loc_code like 'H0%' or (loc_code like 'B%' ) and (count(sku) > 10)

我希望报告只显示值大于 10 的 sku

where-clause sqlanywhere where-in
1个回答
0
投票

您只需将

HAVING
子句添加到查询中即可。

select distinct  batch_date, bol_nbr, cur_opr, lane_nbr, size_code, sku 
loc_code, ship_lab, size_code, sku, COUNT(SKU)
from sherwin.prdinv
where sku IN ('B28W8030', 'B20W12651', 'A87W1351', 'B31W4651', 'A6W151') and (loc_code like 'H0%' or (loc_code like 'B%' ))
and REGEXP_LIKE((SUBSTR(loc_code,3)), '^[[:digit:]]+$')
group by loc_code, ship_lab, SKU, size_code
having COUNT(SKU) < 10
ORDER BY Loc_code asc;
© www.soinside.com 2019 - 2024. All rights reserved.