推 pokl123:感謝 10/15 14:58
※ 引述《pokl123 (00)》之銘言:
: 有兩張table A,B
: [問題]
: 當table A的I1~I4任一欄位符合 table B的k欄位時,
: 且table A的I欄位值不在 table B的S跟F欄位之間,
: 就把table A的result設為Y
: table_A
: I I1 I2 I3 I4 result
: 2555 2749 2554
: 71542 2851 42789 78841 25000
: table_B
: k item S F
: 2554 1 1760 1766
: 2554 2 1790 1796
: 2554 3 2553 2559
: 2554 4 2595 2599
: 2851 1 01580 01596
: 2851 2 01790 01796
: 2851 3 71535 71540
: 2851 4 71550 71555
: 2851 5 71600 71611
: 我目前的想法
: update A
: set result='Y'
: from A,B
: where
: (
: A.I1=B.k AND (I not between B.S and B.F) or
: A.I2=B.k AND (I not between B.S and B.F) or
: A.I3=B.k AND (I not between B.S and B.F) or
: A.I4=B.k AND (I not between B.S and B.F)
: )
updata A
set result = 'Y'
from A,B
where (
(A.I1 = B.k or A.I2 = B.k or A.I3 = B.k or A.I4 = B.k)
and not exists (
select k
from B tmp
where tmp.k = b.k and A.I between tmp.S and tmp.F
)
)
: 但是,這個寫法會沒辦法比較每一筆資料,
: 也就是當比完下面這筆資料後
: 2554 1 1760 1766
: 就直接跳出並把result設為Y了
: 但是因為2555在地第三資料裡面
: 2554 3 2553 2559
: 所以正確的result應該是N
: 請問要如何讓他比對完全部的資料在決定result為多少呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.161.91