0

我有一个有查询的字符串。

问题是我不能只是附加到它,在 where 子句之后有一个 group by。

所以说我得到了这个字符串:

var query = "select stuff from db where something = 3 group by stuff"

现在我想追加"somethingelse > 5 AND "

结果:

query = "select stuff from db where somethingelse > 5 AND something = 3 group by stuff"

我需要做什么才能做到这一点?谢谢

4

2 回答 2

3
query = query.replace(/where/,'where somethingelse > 5 AND');
于 2012-08-14T12:11:19.793 回答
0

如果您按原样传递查询字符串,大卫的回答是最实用的。

或者,如果您自己构建它,最好允许传入选择器列表、查询约束等,以便您最初创建正确的查询字符串。有点像:

val query = "select " + selectors.join() +
            " from " + tables.join() +
            " where " + constraints.join() +
            " group by " + groupings.join()
于 2012-08-14T12:14:47.907 回答