Author | Message |
---|---|
karucla50
Posts: 1
|
Posted 18:14 Oct 20, 2011 |
I've attached the solutions I got for the additional SQL exercises. If anyone has suggestions or other answers, I'd love to see them! |
ataubman
Posts: 3
|
Posted 15:57 Oct 30, 2011 |
i used a right join and boolean statement rather than the subquery you used on Join and functions question 4. -- List the products that nobody has bought in the last three months.
Your subquery:
SELECT description
FROM products p
LEFT JOIN (
SELECT *
FROM orders o, order_details d
WHERE o.id = d.order_id and MONTH(o.date_ordered) >= MONTH(date_sub(current_date(), interval 3 month))
)a ON p.id = a.product_id where a.order_id is null;
My version :
select description from orders o
INNER JOIN order_details od ON o.id = od.order_id
right JOIN products p ON od.product_id = p.id
where (o.date_ordered > subdate(current_timestamp, interval 3 month)) = false or o.date_ordered is null;
;
|