我想做一些像

SELECT * FROM (
    SELECT ('reword#' || reword) || reword_faq as reword FROM me_review_entries re
) as re
WHERE re.reword = 'reword#2#SOME_FAQ'

我试着去做
SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE foo = 'reword#2#SOME_FAQ'

但我得到:
ERROR:  column "foo" does not exist
LINE 2: WHERE foo = 'reword#2#SOME_FAQ'

第一种方法是唯一的方法吗?或者我能改进一下吗?

最佳答案

我认为这取决于您的数据库,但Foo列不存在,除非在查询内,所以您可能必须这样做:

SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE ('reword#' || reword) || reword_faq = 'reword#2#SOME_FAQ'

关于sql - 如何查询构建的字符串选择,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6594309/

10-11 23:48