0
Find a best-selling item along with another. Sql server
TABLE SALE CAMPOS = ttcupomfiscalitem
PRODUCT TABLE FIELDS = ( tcproducts)
I tried to make the following sqlserver query
SELECT TOP (10) c.chavecontrole AS cupom,
p.descricao,
c.produto,
Sum(c.quantidade) AS quantidade
FROM tcprodutos p
INNER JOIN ttcupomfiscalitem c
ON p.produto = c.produto
AND c.produto = '222110165'
GROUP BY c.chavecontrole,
p.descricao,
c.produto
ORDER BY quantidade DESC;
Upshot =
Results appear the same product, how to make appear the other items of the same cumpom by quantity?
you are filtering for only one product...
c.produto = '222110165'
– Rovann Linhalis
@Rovannlinhalis, however wanted to know which product sells the most along with '222110165', How do I pop up the other items of the coupon that has the product = 222110165 on the same coupon. I don’t know if it’s clear. I don’t know how to make this filter.
– programacao 123
Select the distinct "coupon" that has the product x , make a select of these "coupon" ( in , exists etc) counting products other than product x. Count the largest . There must be 564 other possible solutions to this recurring problem. https://answall.com/questions/226495/achar-o-item-mais-vendido-juntamente-com-determinado-item
– Motta
This answers your question? Find the best-selling item along with a particular item
– Sorack