MySql查询出2个字段,在where条件中计算后比较,其中一个字段无法读取到

glartchen
  • 33
SELECT a.something,a.time1,a.time2 FROM `table` AS a WHERE a.time1 < (a.time2 * 60 + 3600);

在这种情况下,计算时无法识别到time2,有没有什么好的方法。

回复
阅读 3.4k
2 个回答

SELECT a.id,a.time1 FROM table as a LEFT JOIN (
SELECT id,time2 FROM table
) as b on b.id=a.id WHERE a.time1<(b.time2*60+3600)

SELECT a.something,a.time1,a.time2 FROM `table` AS a having a.time1 < (a.time2 * 60 + 3600);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏