1 頁 (共 1 頁)

Subquery Syntax

發表於 : 2006-05-16 15:21:49
yehlu
http://dev.mysql.com/doc/refman/5.0/en/subqueries.html

SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);

DELETE FROM t1
WHERE s11 > ANY
(SELECT COUNT(*) /* no hint */ FROM t2
WHERE NOT EXISTS
(SELECT * FROM t3
WHERE ROW(5*t2.s1,77)=
(SELECT 50,11*s1 FROM t4 UNION SELECT 50,77 FROM
(SELECT * FROM t5) AS t5)));

Re: 最後進貨單價

發表於 : 2011-03-14 14:27:59
yehlu
select a.prod_id,a.supply_id,a.stock_order_id,a.price from stock_order_b a join (SELECT prod_id, MAX(stock_order_id) AS aa FROM stock_order_b GROUP BY prod_id)b where a.prod_id = b.prod_id and a.stock_order_id = b.aa;