Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sql如何根据是否在列中找到字符串排序?_Sql_Postgresql - Fatal编程技术网

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中引用别名吗<代码>具有布尔值或(关键字=?)