I am making a query which should return the client's code, name, years and the quantity sold. When I do not perform the filter (which shows me repeated results) I have no problem this is the query:
select c.codigo_cliente, c.nombre, (to_number(to_char(sysdate,'YYYY')) - to_number(to_char(fecha_nacimiento,'YYYY'))) as edad, sum(precio*cantidad)
from clientes c inner join facturacion f on c.CODIGO_CLIENTE = f.CODIGO_CLIENTE
inner join detalle d on f.NUMERO = d.NUMERO;
but when I try not to show the repeated results (group them) I use the following query which gives me the error of invalid identifier in the field AMOUNT, the query I use and shows me the error of the identifier is the following:
select c.codigo_cliente, c.nombre, (to_number(to_char(sysdate,'YYYY')) - to_number(to_char(fecha_nacimiento,'YYYY'))) as edad, sum(precio*cantidad)
from clientes c inner join facturacion f on c.CODIGO_CLIENTE = f.CODIGO_CLIENTE
inner join (select codigo_producto,numero, sum(precio * cantidad) from detalle group by codigo_producto) d on f.numero = d.numero;
I'm working on an Oracle database
I attach the logical diagram of the database:
I thank you for your help.