列出值之间的数量

时间:2016-11-27 08:40:28

标签: oracle-sqldeveloper

我希望列出一系列'之间'的价值观。我只能在一个时刻做一个范围。

SELECT COUNT(WLU.BARCODE) "NO_BARCODES BETWEEN 3001-3002"
FROM WMSLOADUNIT WLU
WHERE WLU.BARCODE BETWEEN '3001000000' AND '3002000000';

我要列出'3002000000'和'3003000000'之间的计数,在'3003000000'和'3004000000'之间,依此类推。你可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我使用CASE语句并使用SUM来计算每个语句中的实例数:

select  
 sum(case when wlu.barcode between '3001000000' and '3002000000' then 1 else 0 end)"BARCODES 3001-3002"
,sum(case when wlu.barcode between '3002000000' and '3003000000' then 1 else 0 end)"BARCODES 3002-3003"
,sum(case when wlu.barcode between '3003000000' and '3004000000' then 1 else 0 end)"BARCODES 3003-3004"
,sum(case when wlu.barcode between '3004000000' and '3005000000' then 1 else 0 end)"BARCODES 3004-3005"
,sum(case when wlu.barcode between '3005000000' and '3006000000' then 1 else 0 end)"BARCODES 3005-3006"
,sum(case when wlu.barcode between '3006000000' and '3007000000' then 1 else 0 end)"BARCODES 3006-3007"
,sum(case when wlu.barcode between '3007000000' and '3008000000' then 1 else 0 end)"BARCODES 3007-3008"
from wmsloadunit wlu
;

RESULTS