MySQL IN 子句中的负值有什么问题?
我有这样的视图:
TABLE_TYPE
(code,name)
(1,'Computer')
(2,'Television')
(3,'Radio')
TABLE_THING
(code,name,type=TABLE_TYPE:code)
(-9999, 'ThingFirst',1)
(1,'Thing1',1)
(2,'Thing2',2)
(3,'Thing3',2)
(4,'Thing4',3)
(5,'Thing5',1)
VIEW_THINGS
(code,name,thingtype)
(-9999, 'ThingFirst','Computer')
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
查询:
select * from VIEW_THINGS where code in (-9999,1,2,3,4,5)
结果是:
(-9999, 'ThingFirst',NULL)
结果应该是:
(-9999, 'ThingFirst','Computer')
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
出了什么问题???
提示 1:当我从 IN 子句中退出负值(-9999)时,我得到:
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
提示 2:如果我从总视图结果中进行选择,我会得到正确的数据:
select * from (select * from VIEW_THINGS as T) where code in (-9999,1,2,3,4,5)
结果:
(-9999, 'ThingFirst','Computer')
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
I have a view like this:
TABLE_TYPE
(code,name)
(1,'Computer')
(2,'Television')
(3,'Radio')
TABLE_THING
(code,name,type=TABLE_TYPE:code)
(-9999, 'ThingFirst',1)
(1,'Thing1',1)
(2,'Thing2',2)
(3,'Thing3',2)
(4,'Thing4',3)
(5,'Thing5',1)
VIEW_THINGS
(code,name,thingtype)
(-9999, 'ThingFirst','Computer')
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
Query:
select * from VIEW_THINGS where code in (-9999,1,2,3,4,5)
Result is:
(-9999, 'ThingFirst',NULL)
Result should be:
(-9999, 'ThingFirst','Computer')
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
WHAT'S WRONG????
Tip1: When I quit the negative value (-9999) from the IN clause I get this:
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
Tip2: If I do the select from the total view results I get the correct data:
select * from (select * from VIEW_THINGS as T) where code in (-9999,1,2,3,4,5)
Results:
(-9999, 'ThingFirst','Computer')
(1,'Thing1','Computer')
(2,'Thing2','Television')
(3,'Thing3','Television')
(4,'Thing4','Radio')
(5,'Thing5','Computer')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完整的测试脚本:
输出
既然这样有效,我就赌 VIEW_THINGS 是一个连接两个表的视图。让我们看看
输出:如上所述,
这是我们所能提供的信息。
Full test script:
Output
Since that works, I'll take a punt that VIEW_THINGS is a view that joins the two tables. Let's see
Output: as above
This is as far as we can go with the info you have provided.
你尝试过改变顺序吗
did you try with changing order like