sql如何根据是否在列中找到字符串排序?
因此,我对一些字符串进行了聚合(使用sql如何根据是否在列中找到字符串排序?,sql,postgresql,Sql,Postgresql,因此,我对一些字符串进行了聚合(使用array\u agg或string\u agg)并将其放入一个新列中 然后我想: order by ("searchString" in columnName) 然而,似乎“in”是一个仅适用于where子句的关键字。我应该用什么来代替 编辑: 让它用布尔鲁或 只需从中选择bool\u或(columnName='keyword'),然后按新列排序即可如果需要精确匹配,可以使用bool\u或() order by bool_or(col = <sear
array\u agg
或string\u agg
)并将其放入一个新列中
然后我想:
order by ("searchString" in columnName)
然而,似乎“in”是一个仅适用于where子句的关键字。我应该用什么来代替
编辑:
让它用布尔鲁或
只需从中选择bool\u或(columnName='keyword'),然后按新列排序即可如果需要精确匹配,可以使用bool\u或()
order by bool_or(col = <search_string>)
按bool\u或(col=)排序
如果需要部分匹配,可以使用如
或正则表达式。如果需要精确匹配,可以使用bool\u或()
order by bool_or(col = <search_string>)
按bool\u或(col=)排序
如果需要部分匹配,可以使用如或正则表达式。可以使用:
但如果columnName
以逗号分隔:
order by position(',searchString,' in concat(',', columnName, ','))
position()
如果在columnName
中找不到'searchString'
,则返回0
在这种情况下,您可能需要一份案例陈述:
order by case position(',searchString,' in concat(',', columnName, ','))
when 0 then 9999 -- or any other large number
else position(',searchString,' in concat(',', columnName, ','))
end
您可以使用:
但如果columnName
以逗号分隔:
order by position(',searchString,' in concat(',', columnName, ','))
position()
如果在columnName
中找不到'searchString'
,则返回0
在这种情况下,您可能需要一份案例陈述:
order by case position(',searchString,' in concat(',', columnName, ','))
when 0 then 9999 -- or any other large number
else position(',searchString,' in concat(',', columnName, ','))
end
这似乎是正确的答案,但我似乎还不能让它发挥作用。它可以识别idx列,但不能识别关键字列select idx,array_agg(关键字)作为关键字我不能在bool_或@JamesJoshuaStreet中引用别名吗<代码>有bool\u或(关键字=?)
。这似乎是正确的答案,但我似乎还不能让它工作。它可以识别idx列,但不能识别关键字列select idx,array_agg(关键字)作为关键字我不能在bool_或@JamesJoshuaStreet中引用别名吗<代码>具有布尔值或(关键字=?)
。