我有一张电话号码表
example:
4685293
+924685293
1254152
我需要选择前两个值作为一个忽略 +92
我可以在查询中执行此操作,还是必须通过我的代码手动执行此操作。
要选择您的本地电话号码,只需使用RIGHT()函数
SELECT DISTINCT RIGHT(phone,7) FROM TABLE
删除要忽略的模式:
REPLACE(example,'+92','')
如果可以有不同的模式,但总是有 3 个字符 (+xx),那么您可以执行以下操作:
CASE WHEN phone LIKE '+[0-9][0-9]%' THEN
RIGHT(phone,LEN(phone)-3)
ELSE
phone
END
您可以尝试仅选择最后 7 个字符...
select distinct(substring(phoneno,-7)) from ...
try this
;with cte as(
select replace(ph,'+92','') as replaced,
ROW_NUMBER() over (order by ph) as rn
from [dbo].[ph]
)
select * from cte where rn <3