Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views1 page

Curva ABC

Uploaded by

Everton Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Curva ABC

Uploaded by

Everton Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SELECT

d2.id_item,
d2.descricao,
CAST(d2.valor_item AS numeric (15,2)) valor_item,
CAST(d2.total_geral AS numeric (15,2)) total_geral,
ROUND(d2.perct, 2) percentual,
d2.perct_acumulado,
CASE -- Definicao dos criterios
WHEN d2.perct_acumulado <= 80.00 THEN 'A'
WHEN d2.perct_acumulado <= 95.00 THEN 'B'
ELSE 'C'
END classe
FROM (
SELECT
d1.id_item,
d1.descricao,
d1.valor_item,
d1.total_geral,
d1.perct,
ROUND(SUM(d1.perct) OVER(ORDER BY d1.perct DESC),2) perct_acumulado
FROM (
SELECT
d.id_item,
d.descricao,
d.valor_item,
SUM(d.valor_item) OVER() total_geral,
CAST(d.valor_item AS numeric (15,3)) / CAST(SUM(d.valor_item) OVER () AS
numeric (15,3)) * 100 perct
FROM (
SELECT
ni.id_item,
i.item_descricao descricao,
SUM((ni.vl_custo * qtd) - vl_desc) valor_item
FROM pedido_itens ni
INNER JOIN pedido p ON p.id = ni.id_pai AND p.faturado = 'S' AND
p.id_filial = 1
AND DATE(p.data_saida) BETWEEN '11.11.2023' AND '31.12.2023'
LEFT JOIN item i ON i.id = ni.id_item
WHERE ni.excluido = false
GROUP BY ni.id_item, i.item_descricao
ORDER BY 3 desc) d) d1) d2

You might also like