sql语句与之间 - 这有什么错呢? [英] Sql statement with BETWEEN - what's wrong with it?

查看:120
本文介绍了sql语句与之间 - 这有什么错呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空(NOT NULL!)我要创建的SQL语句如下:

  SELECT * FROM表WHERE日之间?然后呢? ORDER BY日期ASC LIMIT 1

我在数据库中,因为这一个SQL ^

 光标光标= context.getContentResolver()查询(
                    URI,
                    新的String [] {col_id,COL_2,DATE},
                    DATE +BETWEEN?AND? ,
                    新的String [] {dateAsString,stopDate)},
                    DATE +ASC LIMIT 1);        光标= database.query(
                表,投影,
                选择,selectionArgs两个,
                NULL,NULL,中将sortOrder);

SQL是通过游标为空。我的插件数据库复制到SD卡上,看看它是通过的SQLiteManager 来FF -0所有数据存在及以上控制台作品语句,因此一些与我的sql语句拧。

你能告诉我笏的错wtih呢?

更新延长问题

我店里面有救了作为列日的一些数据:


  1. 2012-11-30 09:12:29.392该模式YYYY-MM-DD HH:MM:S,S

  2. 将其改为长并保存到TEXT类型的列在我的表

  3. 所以我有这样的事情1354197364633

我要得到这行日期DATABSE beetween两个值:

  database.rawQuery(SELECT * FROM赛道,日之间的AND?selectionArgs两个);

但我并不成功的。现在我知道,在任何数据库不工作,但并没有得到解决。你可以建议我怎么能解决我的问题的方式?

我尝试使用下面的解决方案。因此,在光标我得到这个查询:

  SQLiteQuery:(?AS INT)(?AS INT)SELECT * FROM赛道,日之间的CAST和CAST

这个参数mBindArgs:

  {1 = 1354248261841,2 = 1354262663195}

我检查轨道的日期值,它奠定了beyween他们,但还是光标返回空。


解决方案

的原因是我的应用程序逻辑问题:在请求数据库之间的一些框架这一行已经更新,所以我没有得到我的日期

empty (not null!)I want to create sql statement as this:

SELECT * FROM table WHERE date BETWEEN ? AND ? ORDER BY date ASC LIMIT 1

I have a sql in database as this^

            Cursor cursor = context.getContentResolver().query(
                    URI, 
                    new String[] { col_id, col_2,DATE }, 
                    DATE + " BETWEEN ? AND ?" , 
                    new String[] {dateAsString, stopDate)} ,
                    DATE + " ASC LIMIT 1");

        cursor = database.query(
                table, projection, 
                selection, selectionArgs, 
                null, null, sortOrder);

Sql is passed by cursor is null. I copy database to sd card and see it via SQLiteManager plugin to FF -0 all data exists and the statement above works in console, so something wring with my sql statement.

Could you tell me wat's wrong wtih that?

UPDATE extend question

I store some data which has column Date that saved as:

  1. 2012-11-30 09:12:29.392 which pattern yyyy-MM-dd HH:mm:s.S
  2. Convert this to long and save it to TEXT type of columns in my table
  3. So I got something like that 1354197364633

I want to get row which date in databse beetween two values:

database.rawQuery("SELECT * FROM Track WHERE Date BETWEEN ? AND ?", selectionArgs);

But I don't succeeded in it. Now I know that is doesn't work at any database but doesn't got a solution. Could you suggest the way how I can resolve my issue?

I try to use the solution below. So in cursor I get this query:

SQLiteQuery: SELECT * FROM Track WHERE Date BETWEEN CAST(? AS INT) AND CAST(? AS INT)

with this parameters in mBindArgs:

{1=1354248261841, 2=1354262663195}

I check the date value in track, it lays beyween them, but cursor still returned empty.

解决方案

The cause is issue in logic of my app: in some frame between requests to database this rows have been updated so I haven't got my date.

这篇关于sql语句与之间 - 这有什么错呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆