我正在尝试查询ID_NUMBER
中TBL_TRANSACTIONS
所做的交易
并且要求确保ID_NUMBER
中存在TBL_ID_NUMBER
。
SELECT *
FROM TBL_TRANSACTIONS
WHERE ID_NUMBER IN ( SELECT ??????
FROM TBL_ID_NUMBER)
问题是ID号是否在范围内,例如10-50
,51-90
,91-100
有没有办法可以查询这两列之间的数字?我们说ID_NUMBER
是19?
TBL_ID_NUMBER (table)
ID_FROM (column1) ID_TO (column2)
10 50
答案 0 :(得分:0)
我不知道你是不是这样,但是有一个建议;)
SELECT *
FROM TBL_TRANSACTIONS
WHERE ID_NUMBER >= ( SELECT ID_FROM
FROM TBL_ID_NUMBER
WHERE
ID_NUMBER = 19)
AND ID_NUMBER <= ( SELECT ID_FROM
FROM TBL_ID_NUMBER
WHERE
ID_NUMBER = 19)
编辑:我不知道您的数据库结构,所以这是另一个建议
SELECT *
FROM TBL_TRANSACTIONS
WHERE ID_NUMBER >= ( SELECT ID_FROM
FROM TBL_ID_NUMBER
WHERE
ID_FROM <= 19
AND
ID_TO >= 19)
AND ID_NUMBER <= ( SELECT ID_TO
FROM TBL_ID_NUMBER
WHERE
ID_FROM <= 19
AND
ID_TO >= 19)