1
resposta

[Projeto] Solução

Segue a forma que fiz.

select tc.nome,
    tc.cpf, 
    CONVERT(VARCHAR(7), NF.DATA_VENDA, 120) as ref,
    sum(inf.QUANTIDADE) as QtdVendida,
    tc.VOLUME_DE_COMPRA as VlCompraMax,
case 
    when sum(inf.QUANTIDADE) > tc.VOLUME_DE_COMPRA then 'Ultrapassou o limite'
    when sum(inf.QUANTIDADE) < tc.VOLUME_DE_COMPRA then 'Dentro do limite'
end as SituacaoLimite,
round((1-(tc.VOLUME_DE_COMPRA/sum(inf.QUANTIDADE)))*100, 2) as Pct
from ITENS_NOTAS_FISCAIS inf
join NOTAS_FISCAIS nf on inf.NUMERO = nf.NUMERO
join TABELA_DE_CLIENTES tc on nf.CPF = tc.CPF
group by CONVERT(VARCHAR(7), NF.DATA_VENDA, 120), tc.NOME, tc.CPF, tc.VOLUME_DE_COMPRA
HAVING sum(inf.QUANTIDADE) > tc.VOLUME_DE_COMPRA
order by tc.NOME, tc.CPF, CONVERT(VARCHAR(7), NF.DATA_VENDA, 120)
1 resposta

Oi, Diego! Tudo bem?

Parabéns pelo desenvolvimento da atividade! Testei e analisei o seu SELECT e ele está correto, mandou muito bem!

Continue sempre com essa dedicação em seus estudos, conte comigo em caso de dúvidas.

Abraços!