Pregunta

I have the following problem in my sqlite database there are values stored and for some purposes I need to remove entries. But before I need to get the id for the rows which I would like to remove. To get the id tried to use the following query:

select commonid from TestData where coordinate_x=5.707523 and coordinate_y=6.693941;

The result is zero, because the value for coordinate_y is 6.693940. Therefore I was thinking to use like to get the right result. It does not matter, because the values do not difference only in the first two digits after the comma. I tried:

select commonid from TestData where coordinate_x=5.707523 and coordinate_y LIKE "6.69394%";

This failed either and the result was zero.

I figured out in the internet that I could use * instead of %.

select commonid from TestData where coordinate_x=5.707523 and coordinate_y LIKE "6.69394*";

Unfortunately this did not work too.

So how can I use like or any other command to solve this problem?

¿Fue útil?

Solución

This works for me:

sqlite> .schema t
CREATE TABLE t (f double);
sqlite> select * from t;
1.23456789
2.23456789
3.23456789
sqlite> select * from t where f = 1.23456789;
1.23456789
sqlite> select * from t where f like '1.23456789';
1.23456789
sqlite> select * from t where f like '1.234%';
1.23456789
sqlite> select * from t where f like '_.23456789';
1.23456789
2.23456789
3.23456789

Otros consejos

You can, but it would be smarter (and probably faster) to do

SELECT commonid FROM TestData WHERE coordinate_x=5.707523 AND
    ABS(coordinate_y-6.693945)<0.000005;

or

SELECT commonid FROM TestData WHERE coordinate_x=5.707523 AND
    coordinate_y BETWEEN 6.69394 AND 6.69395;

Try treating as character

select commonid from TestData 
where coordinate_x=5.707523 
and Cast(coordinate_y as Char(100)) LIKE "6.69394%";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top