0
using SQL Server
I have made the following select to select products purchased by customers:
select ITEMPEDIDO.IDPEDIDO, ITEMPEDIDO.QUANTIDADE, CLIENTE.NOME
from ITEMPEDIDO, cliente, pedido
where PEDIDO.IDPEDIDO=ITEMPEDIDO.IDPEDIDO AND CLIENTE.IDCLIENTE = PEDIDO.IDCLIENTE
order by ITEMPEDIDO.QUANTIDADE desc
outworking :
IDPEDIDO QUANTITY NAME
5 3 Adrina Domingues
1 1 Edivaldo Santana
2 1 José Antonio
3 1 Hugo Batista
3 1 Hugo Batista
4 1 Cristina Oliveira
1 1 Edivaldo Santana
2 1 José Antonio
now I intend to add the quantity items depending on the requested id, however this giving error.
select ITEMPEDIDO.IDPEDIDO, sum (ITEMPEDIDO.QUANTIDADE), CLIENTE.NOME from ITEMPEDIDO, cliente, pedido
where PEDIDO.IDPEDIDO=ITEMPEDIDO.IDPEDIDO AND CLIENTE.IDCLIENTE = PEDIDO.IDCLIENTE
group by ITEMPEDIDO.IDPEDIDO
order by ITEMPEDIDO.QUANTIDADE desc --FETCH NEXT 1 ROWS ONLY
error msg :
ORA-00979: not a GROUP BY Expression
This ORDER BY clause does not make sense with the GROUP BY / SUM specified.
– anonimo
If you want to order by
sum (ITEMPEDIDO.QUANTIDADE)
you can use, for this query, the number 2 (the second field of the selection list). Also its ORDER BY clause should specify ITEMPEDIDO.IDPEDIDO and CUSTOMER.NAME to make sense.– anonimo