You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改查询,为结尾是特定字符(如F1)的结果追加指定字符(如HR)?

Solution to Append "HR" to Results Ending with "F1"

Hey there! Let's work through this problem step by step. You need to tweak your query so any result ending with "F1" gets "HR" added to the end, while leaving other results exactly as they are. Here's how to pull this off in most common SQL dialects:

Modified Query Example

Assuming your original query selects a column (let's call it target_column) from a table named your_table, here's the adjusted version:

SELECT
  CASE
    WHEN RIGHT(target_column, 2) = 'F1' THEN CONCAT(target_column, 'HR')
    ELSE target_column
  END AS modified_result
FROM your_table;

Breakdown of the Logic

  • RIGHT(target_column, 2): This grabs the last 2 characters of the value in target_column to check if it ends with "F1".
  • CASE WHEN ... THEN ... ELSE ... END: This conditional checks the ending characters. If they match "F1", it uses CONCAT to append "HR"; otherwise, it returns the original value untouched.
  • AS modified_result: Renames the output column to make it clear which values were adjusted (feel free to change this to a name that fits your use case).

Example Scenario

Current Query Results:

  • ABC123
  • XYZF1
  • DEF456
  • GHIJF1

Expected Results:

  • ABC123
  • XYZF1HR
  • DEF456
  • GHIJF1HR

If your original query includes more columns or complex filtering, you can just drop this CASE statement right into your select clause wherever the target column is being pulled.

内容的提问来源于stack exchange,提问作者Chris Kiriakidis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:17:05