我對如何完成此查詢完全感到困惑。按組合更新查詢並設置最短日期
如何實現這個查詢沒有大的性能影響(如果表包含數千行)?
請指教!
MyTable的
pktimestmp | sw_id | url_id | open_date | end_date
-------------------------------------------------------
xxx0 | 101 | com | 2013-01-01 | 2013-01-30
xxx1 | 202 | net | 2013-01-01 | 2013-01-30
xxx2 | 202 | net | 2013-01-15 | 2013-02-28 *
xxx3 | 303 | com | 2013-01-01 | 2013-01-30
xxx4 | 303 | com | 2013-02-01 | 2013-02-15 *
xxx5 | 303 | com | 2013-03-01 | 2013-03-15 *
xxx6 | 404 | org | 2013-01-01 | 2013-01-30
xxx7 | 404 | org | 2013-02-01 | 2013-02-15 *
xxx8 | 404 | gov | 2013-02-01 | 2013-02-15
xxx9 | 404 | gov | 2013-02-01 | 2013-02-15
...
更新查詢上:其中軟件和URL是相同的
日期(即SW_ID和url_id)。
我們將opendate和enddate設置爲less(min)發生。
xxx2 | 202 | net | 2013-01-15 | 2013-02-28
will be
xxx2 | 202 | net | 2013-01-01 | 2013-01-30
here we have updated
open_date to min(open_date)
and
end_date to min(end_date)
from same sw and url.
(這將是很好,如果我們只更新是有區別的, 例如沒有必要,因爲它們是「相同的」更新xxx8和xxx9)
MyTable的 (* =更新行)
pktimestmp | sw_id | url_id | open_date | end_date
-------------------------------------------------------
xxx0 | 101 | com | 2013-01-01 | 2013-01-30
xxx1 | 202 | net | 2013-01-01 | 2013-01-30
xxx2 | 202 | net | 2013-01-01 | 2013-01-30 *
xxx3 | 303 | com | 2013-01-01 | 2013-01-30
xxx4 | 303 | com | 2013-01-01 | 2013-01-30 *
xxx5 | 303 | com | 2013-01-01 | 2013-01-30 *
xxx6 | 404 | org | 2013-01-01 | 2013-01-30
xxx7 | 404 | org | 2013-01-01 | 2013-01-30 *
xxx8 | 404 | gov | 2013-02-01 | 2013-02-15
xxx9 | 404 | gov | 2013-02-01 | 2013-02-15
在此先感謝! (而且沒有我沒權重模型表):)
任何幫助表示讚賞,網址,提示,電子書,網站...
...嘿,這與行'xxx7'了?結束日期實際上是_increased_(到「過去」日期,不得少於)。這應該是'2013-02-15'嗎? –
是的,它應該是02-15,它是固定的。任何想法的更新查詢? :\ – MrSimpleMind