SQL orders last quarter [duplicated]

0

How can I know the orders of the last quarter given this question and this relational database

Would it be like this?

SELECT ID_PRODUCTO FROM PRODUCTOS 
    WHERE ID_PRODUCTO IN ( SELECT ID_PRODUCTO FROM PEDIDOS 
                        WHERE FECHA>SYSDATE-90)

How can I find it without problems afterwards for months ending in 31?

    
asked by user7407723 04.03.2018 в 18:47
source

1 answer

2

The condition of WHERE is fine (you only have to change the '>' for a '> =' otherwise you might not consider some cases), only that you are only getting the products. In case you want data of the order and the product you should link both tables:

SELECT p.ID_PEDIDO, p.CANT, p.FECHA, pr.DESCRIPCION FROM PEDIDOS p # Obtengo id del pedico, cantidad, fecha y descripcion del producto pedido
INNER JOIN PRODUCTOS pr ON pr.ID_PRODUCTO = p.ID_PRODUCTO # Uno las tablas
WHERE p.FECHA >= SYSDATE-90 # Ultimo trimestre

It will be enough to put the attributes you need in case the ones in the example are few.

I hope it was helpful!

Greetings!

    
answered by 04.03.2018 в 19:06