0

I have a table like so:


    Type    Col1
    0       ff
    1       9f
    3       92
and I want to access just a part of the col1 values

i.e. I want to query the table with a value such as Col1=92 where all the rows return and if I queried with Col1=94 then row 0 and 1 would return and if I queried with Col1=12 only row 0 would return. Obviously some operation would need to happen on the above assignment statements for this to work.

so something like this: SELECT * FROM TABLE1 WHERE Col1(1)=9;except I understand that sintax does not work...

hope this makes sense

4

3 回答 3

1

您至少有 3 个选项

首先是

where `col1` like '9%'

第二

where substr(`col1`,1,1) = "9"

第三

where left(`col1`, 1) = "9" 
于 2013-06-27T19:34:38.897 回答
0

假设 col1 是一个文本字段,你可以这样做:

SELECT * FROM table1 WHERE col1 LIKE '9%';

返回 col1 以 9 开​​头的任何行。

有关更多“LIKE”模式,请参阅http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

于 2013-06-27T19:33:27.273 回答
0

或者,您可以使用 substr(string, start, length),所以它是:

SELECT * FROM table1 WHERE substr(col1,1,1)='9'
于 2013-06-27T19:36:20.677 回答