这个 MYSQL 查询有什么问题
SELECT * FROM event JOIN user ON event.event_user_id=user.user_id
WHERE ((event.event_date BETWEEN '2011-03-01' AND '2011-04-01' )
AND user.user_id in (SELECT user_id FROM user_map
WHERE (user_map.user_id_map=1 AND user_map.user_relation<=7)));
这在 Toad/MYsql 中工作正常,但当我使用 java + mysql 驱动程序中的准备好的语句执行此操作时失败
SELECT * FROM event JOIN user ON event.event_user_id=user.user_id
WHERE ((event.event_date BETWEEN ? AND ? )
AND user.user_id in (SELECT user_id FROM user_map
WHERE (user_map.user_id_map=? AND user_map.user_relation<=?)));
...
pstmt.setDate(1, <sqlDate>);
pstmt.setDate(2, <sqlDate>);
pstmt.setLong(3, <int>);
pstmt.setLong(4, <int>);
pstmt.executeQuery();
SELECT * FROM event JOIN user ON event.event_user_id=user.user_id
WHERE ((event.event_date BETWEEN '2011-03-01' AND '2011-04-01' )
AND user.user_id in (SELECT user_id FROM user_map
WHERE (user_map.user_id_map=1 AND user_map.user_relation<=7)));
This is working fine in Toad/MYsql but fails when I do it with prepared statement in java + mysql driver as
SELECT * FROM event JOIN user ON event.event_user_id=user.user_id
WHERE ((event.event_date BETWEEN ? AND ? )
AND user.user_id in (SELECT user_id FROM user_map
WHERE (user_map.user_id_map=? AND user_map.user_relation<=?)));
...
pstmt.setDate(1, <sqlDate>);
pstmt.setDate(2, <sqlDate>);
pstmt.setLong(3, <int>);
pstmt.setLong(4, <int>);
pstmt.executeQuery();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它与问题没有密切关系,但查询效率不高,可以改进,
您需要
It is not closely related to problem but the query is not efficient and can be improved
you need indexes on