Subquery Syntax

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Subquery Syntax

文章 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)));
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Re: 最後進貨單價

文章 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;
回覆文章

回到「MySQL」