我是第一次发帖。
我一直试图找出这份报告的问题。在此报告中,我想显示最近已售出但未退回(+ 非 - 价格)的产品的序列号。
我想检查一个产品是否被标记为已售出,如果它最后售出并且没有最后退回。
这就是我所做的,我想我可能需要对其进行子查询,但我无法弄清楚第一部分。
SELECT
ps.serial,p.upc,p.name,so.date_sold
FROM
store_orders so
LEFT JOIN store_order_products sop ON so.id = sop.order_id
LEFT JOIN products p ON sop.product_id = p.id
LEFT JOIN product_serials ps ON ps.serial = sop.product_serial
WHERE
(CAST(so.date_sold AS DATE) BETWEEN '2013-4-15' AND '2013-5-15')
AND ps.deleted = '0' AND sop.price > 0
ORDER BY
sop.id DESC
LIMIT 10
它正在退回可能最后退回的产品,而不是最后售出的产品。
`ID Serial Price
1: 8332-83 10.00
2: 8332-83 -10.00
Dont want to see this because it was returned last, not sold last
ID Serial Price
2: 8332-82 10.00
1: 8332-82 -10.00
This was sold last not returned so looking to see this serial`
请帮忙。提前致谢。乔