我有如下数据集:
table_a
Product_Name Product_Orders
game_296 1
game_298 2
game_299 4
300_game 6
xyz_game 9
game-tyw 12
如何在 SQL 中使用 like
函数并与大于号结合使用?我的总体目标是过滤大于特定数字(如 297)的游戏。
理想情况下,我想做这样的事情:
select * from table_a
where Product_Name > ilike %297%
这里的预期输出是这样的:
Product_Name Product_Orders
game_298 2
game_299 4
300_game 6
最佳答案
一种方法是从字符串中删除所有非数字,然后进行比较:
where cast(regexp_replace(product_name, '[^0-9]', '') as int) > 297
https://stackoverflow.com/questions/67994107/