我有一列,调用'expected_salary'。按名称,它假设是一些数值。但是,我也希望它具有“竞争性”,“基于佣金”等价值,因此,它变成了一种字符串类型。查询字符串列
现在愚蠢的问题是,我想查询它,如SELECT all rows where expected_salary >= 3000
。当然,它不能用于正常的数字比较。
在将'expected_salary'转换为整数类型并创建额外的列调用'other_salary'之前,我想知道是否有更好的解决方案。
我有一列,调用'expected_salary'。按名称,它假设是一些数值。但是,我也希望它具有“竞争性”,“基于佣金”等价值,因此,它变成了一种字符串类型。查询字符串列
现在愚蠢的问题是,我想查询它,如SELECT all rows where expected_salary >= 3000
。当然,它不能用于正常的数字比较。
在将'expected_salary'转换为整数类型并创建额外的列调用'other_salary'之前,我想知道是否有更好的解决方案。
当然,创建额外的列,可能是布尔值,默认为false。 is_commissioned
,is_competitive
等
然后适当的查询是
SELECT *
FROM table
WHERE expected_salary >= 3000 AND is_competitive
你可以有限定值。
例如:
为expected_salary = '3000, salary comments'
。
你可以试试下面的查询。
SELECT *
FROM table
WHERE CAST(SUBSTRING(expected_salary, 0, PATINDEX('%,%',expected_salary)) as INT) >= 3000
猜测:
create table salaries (
expected_salary text
);
insert into salaries values ('1000'),('1500,comment'),('3000,comment'),('3500'),
('comment'),('4000'),('4500,comment');
您可以使用substring()
函数从string
select * from (
select substring(expected_salary FROM '[0-9]+')::int sal from salaries
) t where sal >=3000;
在其中添加提取Integer
“和expected_salary不” 的价值观,可以与数字相比较。
'选择所有行where expected_salary :: numeric> = 3000'?如果可能的话,提供样品表和数据 –