我有一个有查询的字符串。
问题是我不能只是追加它,在where子句之后有一个分组。
所以说我给了这个字符串:
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"
我需要做什么才能做到这一点?感谢
答案 0 :(得分:3)
query = query.replace(/where/,'where somethingelse > 5 AND');
答案 1 :(得分:0)
David's answer是最实用的。
或者,如果您自己构建它,最好允许传入选择器列表,查询约束等,以便您最初创建正确的查询字符串。有点像:
val query = "select " + selectors.join() +
" from " + tables.join() +
" where " + constraints.join() +
" group by " + groupings.join()