我正在研究产生不同价值的mysql查询。
一个就像
select column1 from table1 where condition1
另一个是
select column2 from table1 where condition2
两个查询都返回一个int。我想找到这两者的不同之处。
尝试减去,相交,但他们在mysql语法中说错误。
原始查询:
SELECT (SELECT MAX(date_time) maxDate FROM history WHERE ID = 2593 AND from = 1) - SELECT (SELECT MIN(date_time) minDate FROM history WHERE ID = 2593 AND to = 13)
答案 0 :(得分:3)
尝试:
select (select column1 from table1 where condition1)-(select column2 from table1 where condition2)
答案 1 :(得分:2)
您应该转换返回的值
((int) select column1 from table1 where condition1) - ((int) select column2 from table1 where condition2)
或double而不是int,取决于你