作者smlboby (波比)
看板Database
标题Re: [SQL ] 关联查询的问题?
时间Thu Jul 28 00:00:20 2011
※ 引述《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
1F:推 terrybob:谢谢,已试过,可达到效果! 07/28 10:08