0
I have two tables.
Table:
Pedido
- Columns:
IDPEDIDO
,CLIENTE
,DT_PEDIDO
,FORMA_PGMT
,CLIENTE_ID
.
- Columns:
Table:
Itens_Pedido
- Columns:
PEDIDO_ID
,QT_MERCADORIAS
,MERCADORIA
,MERCADORIA_ID
.
- Columns:
I need to create a query to know which product is the most sold in January and February 2015. I made the query below but she is returning me this error:
"not a single-group group Function"
Consultation:
Select max(sum(ITENS_PEDIDO.QT_MERCADORIA)),
ITENS_PEDIDO.MERCADORIA
From ITENS_PEDIDO
Join PEDIDO
On ITENS_PEDIDO.PEDIDO_ID = PEDIDO.IDPEDIDO
Group By ITENS_PEDIDO.MERCADORIA_IDMERCADORIA,
ITENS_PEDIDO.MERCADORIA,
PEDIDO.DT_PEDIDO
Having PEDIDO.DT_PEDIDO Between to_date('01/01/2015', 'DD/MM/YYYY')
And to_date('28/02/2015', 'DD/MM/YYYY');
According to that answer in Soen you are using columns that are being used in aggregate functions in GROUP BY. Try redoing your query without including
ITENS_PEDIDO.QT_MERCADORIA
at GROUP BY;– user28595
This works... the problem is that if I don’t put ITENS_PEDIDO.QT_MERCADORIA it only shows the best selling quantity and does not show the product name.
– Thiago Meira
Try to remove the
max()
, create an alias like thissum(ITENS_PEDIDO.QT_MERCADORIA) as total_mercadoria
to useorder by total_mercadoria desc limit 1
.– user28595
It did not work a result 50 that I can not understand why, the sum will never give 50
– Thiago Meira