2014-12-26 115 views
0

我有一列,調用'expected_salary'。按名稱,它假設是一些數值。但是,我也希望它具有「競爭性」,「基於佣金」等價值,因此,它變成了一種字符串類型。查詢字符串列

現在愚蠢的問題是,我想查詢它,如SELECT all rows where expected_salary >= 3000。當然,它不能用於正常的數字比較。

在將'expected_salary'轉換爲整數類型並創建額外的列調用'other_salary'之前,我想知道是否有更好的解決方案。

+0

'選擇所有行where expected_salary :: numeric> = 3000'?如果可能的話,提供樣品表和數據 –

回答

3

當然,創建額外的列,可能是布爾值,默認爲false。 is_commissionedis_competitive

然後適當的查詢是

SELECT * 
FROM table 
WHERE expected_salary >= 3000 AND is_competitive 
0

你可以有限定值。

例如:

爲expected_salary = '3000, salary comments'

你可以試試下面的查詢。

SELECT * 
FROM table 
WHERE CAST(SUBSTRING(expected_salary, 0, PATINDEX('%,%',expected_salary)) as INT) >= 3000 
0

猜測:

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; 
0

在其中添加提取Integer 「和expected_salary不」 的價值觀,可以與數字相比較。