SQL-类似和大于函数
我有一个如下所示的数据集:
table_a
Product_Name Product_Orders
game_296 1
game_298 2
game_299 4
300_game 6
xyz_game 9
game-tyw 12
如何like在 SQL 中使用函数并与大于号组合?我的总体目标是过滤大于某个数字(如 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