Ö´ÐÐsql - PowerBuilder / Êý¾Ý¿âÏà¹Ø
update test set qty = qty - 1 where (location,sku,valid_date)
in (select location,sku,min(valid_date) from test
where location = 'chuwei' and item_code = '5678' group by location,sku)
ÒÔÉÏÓï¾äÔÚpbÖÐÓÃÏÂÁз½Ê½Ö´ÐРΪʲôµÚÒ»Ìõ¼Ç¼ûÓÐupdate
Execute Immediate :as_sql Using atran_ex
ÄãÊÇÏëÈÃÏàͬµÄlocation,skuÖУ¬×îСµÄvalid_dateÄÇÌõ¼Ç¼ÖÐqty-1?
ÒÔÏÂÁ½ÖÖ·½·¨¶¼ÐС£
update test
set qty = qty - 1
from test t where valid_date =
(select min(valid_date) from test where location = t.location and sku = t.sku)
update test
set qty = qty - 1
from test t where not exists
(select 1 from test where location = t.location and sku = t.sku and valid_date < t.valid_date)
update test set qty = qty - 1
where item_code = '5678'
and valid_date=(
select min(valid_date) from test a
where a.location= location and a.sku=sku )
)
Ïà¹ØÎÊ´ð£º
ÎÒÒ»¸öÏîÄ¿£¬Óиö²åÈë²Ù×÷£¬¾ßÌåÊÇÕâÑùµÄ£º
ÎÒÓнø»õÐÅÏ¢±í¡£ÔÚ³ö»õʱѡÔñÏàÓ¦µÄ½ø»õÐÅÏ¢£¬ÊäÈëÊýÁ¿£¬Ñ¡Ôñ²¿Ãź󣬵㱣´æ°´Å¥£¬ÓÉÓÚÍøÂçÑÓʱ£¬µãÒ»ÏÂûÓз´Ó³£¬ÓÚÊÇÓû§¾ÍÓÖµãһϣ¬µ¼ÖÂÒ»´Î²åÈëÁËÁ½Ìõ¼Ç¼:
Àý£º
......
³¡¾°ÈçÏ£º
¿Í»§°Ñ±¸·ÝºÃµÄÊý¾Ý¿â£¬·¢¸øÎÒ£¬ÎÒÔÚ±¾»ú»¹Ôºó£¬ÔËÐÐдºÃµÄ´æ´¢¹ý³Ì£¬±È½Ï¿ì£¬²¢ÇÒÔÚʵʩÄDZßÔËÐÐͬÑù±È½Ï¿ì¡£µ«Êǵ±ÊµÊ©ÔÚ¿Í»§ÄDZßÔËÐеÄʱºòËٶȾͷdz£µÄÂý£¬Ê±¼ä³¬³öÁ˳ÌÐòµÄʱ¼äÏÞÖÆ¡£Ô¶³ÌÔÚ¿Í»§ÄÇ ......
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
Á½¸ö±í
Çë¿´ "Persons" ±í£º
name banji shunxu
yiyang 01 1
yiyang 02 1
lili 01 2
½ÓÏÂÀ´Çë¿´ "xueke" ±í£º
name kemu shunxu
yiy ......