我有两个SELECT语句:
SELECT Termin FROM crSpielTermine WHERE Status = 1
和这个
SELECT TerminID FROM crSpielTermine WHERE Termin > ".$AlterTermin." ORDER BY Termin LIMIT 1
现在,第一个选择为我$AlterTermin
提供了我正在使用的 function tick() {
path.attr("d", function(d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" +
d.source.x + "," +
d.source.y + "A" +
dr + "," + dr + " 0 0,1 " +
d.target.x + "," +
d.target.y;
});
第二个陈述。
我可以将这两个陈述合并,如果是,我将如何做到这一点?
答案 0 :(得分:3)
假设您的第一个选择仅返回一个项目,您就会有类似的内容:
SELECT TerminID
FROM crSpielTermine
WHERE Termin > (SELECT Termin FROM crSpielTermine WHERE Status = 1)
ORDER BY Termin
LIMIT 1
或者这只是为了确保它只返回一个项目
SELECT TerminID
FROM crSpielTermine
WHERE Termin > (SELECT Termin FROM crSpielTermine WHERE Status = 1 LIMIT 1)
ORDER BY Termin
LIMIT 1
答案 1 :(得分:2)
您可以使用如下的子查询,这将得到相同的结果:
SELECT TerminID FROM crSpielTermine
WHERE Termin > (SELECT Termin FROM crSpielTermine WHERE Status = 1)
ORDER BY Termin LIMIT 1