求大神给个sql语句。。。

需要查一天内00:00:00到02:00:00等十二个时间段内每段一条数据,求指教

3个回答

0点到早上2点的嘛?十二个时间段是怎么分的啊?
private void QueryTime(Object object){
String colums = {“xx”,“cc”,“vv”,“bb”};
Cursor cursor = mDb.Query("表名",colums,"object="+object,null,null,null,null,null);
while(cursor.moveToNext){
Object obj = cursor.get...(cursor.getC("xx"));
Object obj = cursor.get...(cursor.getC("cc"));
Object obj = cursor.get...(cursor.getC("vv"));
Object obj = cursor.get...(cursor.getC("bb"));
}
cursor.close()
}

for( int i =0;i<12;i++){
QueryTime(object);
}
大概就是这样咯,把你的时间段12等分(如果可以的话),用个循化来执行查询数据库(sqlite)的操作 ,剩下的就是数据的组装了。如果错了别打脸,好吧……╮(╯-╰)╭。

qq_36522073
qq_36522073 这代码是SQLite语句,你如果想查的是My sql的那就用三楼大神那段
3 年多之前 回复
qq_36522073
qq_36522073 如果真的按你的标题说的那样 查询12时间段的每一条数据 那循环就是12次咯
3 年多之前 回复
zparkdong
zparkdong 循环查询数据库就是要查12次吗?
3 年多之前 回复

SQL的写法:

 select '0-2' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 0:00:00' and '2016-11-24 2:00:00'
union all
select '2-4' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 2:00:00' and '2016-11-24 4:00:00'
union all
select '4-6' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 4:00:00' and '2016-11-24 6:00:00'
union all
select '6-8' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 6:00:00' and '2016-11-24 8:00:00'
union all
select '8-10' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 8:00:00' and '2016-11-24 10:00:00'
union all
select '10-12' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 10:00:00' and '2016-11-24 12:00:00'
union all
select '12-14' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 12:00:00' and '2016-11-24 14:00:00'
union all
select '14-16' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 14:00:00' and '2016-11-24 16:00:00'
union all
select '16-18' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 16:00:00' and '2016-11-24 18:00:00'
union all
select '18-20' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 18:00:00' and '2016-11-24 20:00:00'
union all
select '20-22' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 20:00:00' and '2016-11-24 22:00:00'
union all
select '22-24' as T,column1,column2,column3... from TableName where TimeColumn between '2016-11-24 22:00:00' and '2016-11-25 0:00:00'

需要结合实际数据啊,把你的表贴出来才能给你具体sql,别光提个问题,谁知道你问的鸟啊

zparkdong
zparkdong 问的你
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问