我正在嘗試學習 SQL 并找出一種方法來檢索名稱以串列中的一個字符結尾的所有列(使用 JDBC 查詢):
public Map<Long, Set<Long>> groupCountriesBy(Set<Integer> countryIdLastDigits) {
String query = "SELECT c.id FROM countries c"
" WHERE c.name LIKE '%[dea]'"
" GROUP BY c.name ";
var args = new MapSqlParameterSource("countryIdLastDigits", countryIdLastDigits);
....
}
WHERE c.name LIKE '%[dea]'會回傳所有以 d、e 或 a 結尾的列,但我沒能找到將 countryIdLastDigits 傳遞給此 SQL 查詢的方法。
你能和我分享一些指示/提示嗎?可能我遺漏了一些 SQL 概念/命令。
uj5u.com熱心網友回復:
大多數 SQL 方言都有左右字串函式,所以可能類似于
where right(col,1) in ('d', 'e', 'a')
將是你所需要的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/535297.html
上一篇:回傳關于更新sql的復雜查詢
