选择from和to之间的值

时间:2016-09-28 06:58:10

标签: sql sql-server vb.net

SELECT Q.mem_id
FROM   tb_mem_share Q,
       tb_member Mb
WHERE  Mb.mem_id = Q.mem_id
       AND Q.share_num_from BETWEEN '42368' AND '42378'

SELECT *
FROM   tb_mem_share
WHERE  share_num_from >= 42368
       AND share_num_from <= 42378

运行这个我只获得第二条记录:

   mem_id   |  share_num_from  |  share_num_to  |  no_of_shares  |  share_amt
 -----------+------------------+----------------+----------------+--------------
  KA003871  |       42360      |     42369      |     10         |    10000
  KA000401  |       42370      |     42379      |     10         |    10000

我做错了什么?

2 个答案:

答案 0 :(得分:2)

第一条记录中的

share_num_from是42360,不在“42368”和“42378”之间

答案 1 :(得分:1)

不确定您要执行的操作,但是如果您想根据来自&amp;和/或至于列,您至少应该在您的选择中包含它们:

SELECT *
FROM tb_mem_share
WHERE share_num_from >= 42368
  AND share_num_to <= 42378;

目前您正在过滤两次。