推 terrybob:謝謝,已試過,可達到效果! 07/28 10:08
※ 引述《terrybob (罪雲樵)》之銘言:
: [table_a]
: id int1 int2 (int1 幾分以下通知, int-幾分以上通知)
: 1 10 60
: 2 20 70
: 3 30 80
: 4 40 90
: 5 50 70
: 6 0 0
: 7 0 0
: 8 0 0
: ---------------
: [table_b]
: id score
: 1 20
: 2 60
: 3 80
: 4 100
: 5 50
: 6 90
: 7 80
: 8 100
: ---------------
: 我想利用table_a.int1、int2的值,
: 去跟table_b.score欄位進行比對…(小於int1,大於int2)的結果顯示,
: 而若需要達成顯示,目前是由程式進行運算,但這就會影響到頁面的筆數…
: 因為有比對完後,內容筆數不一定會跟sql一樣…
: 所以希望由sql方式進行查詢,
: 我目前只作到:
: select table_a.*, table_b.score from table_a,table_b
: where table_a.id=table_b.id and table_a.int1>0 and table_a.int2>0
: 還想不出實際比對score的動作…
: 請高手們指教,謝謝。
select id,score
from table_b
where exists (
select 1
from table_a
where table_a.id = table_b.id
and (table_b.score < table_a.int1
or table_b.score > table_a.int2)
)
不知道這是不是你要的...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.193.216.209