Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取具有相同其他列值的两个连续行的列值_Java_Android_Mysql_Sql - Fatal编程技术网

Java 获取具有相同其他列值的两个连续行的列值

Java 获取具有相同其他列值的两个连续行的列值,java,android,mysql,sql,Java,Android,Mysql,Sql,第1列:日期第2列:类型 因此,如果行按日期降序排列,则查找用户具有相同连续类型的日期(参见下面的示例) 例如: 如果我的表包含以下数据- Sr Date Type 1 2013-05-24T16:21:06.728Z Alaska 2 2013-05-27T20:44:32.412Z Clever 3 2013-05-27T20:45:33.301Z Clever 4

第1列:日期
第2列:类型

因此,如果行按日期降序排列,则查找用户具有相同连续类型的日期(参见下面的示例)

例如:

如果我的表包含以下数据-

  Sr   Date                            Type

  1  2013-05-24T16:21:06.728Z       Alaska

  2  2013-05-27T20:44:32.412Z       Clever

  3  2013-05-27T20:45:33.301Z       Clever

  4  2013-05-27T21:45:46.127Z       Clever

  5  2013-05-27T21:46:27.825Z       Self
6 2013-05-28815:18:48.430Z

所以我想要日期
2013-05-27T21:45:46.127Z

我尝试了以下方法-

ArrayList<String> startTimeList = new ArrayList<String>();
cur = dbAdapter.rawQuery("select Date, Type from User ORDER BY Date DESC", null);

cur.moveToFirst();

if(cur.getCount() > 0)
{
    int i = 0;

    while(cur.isAfterLast() == false)
    {
        if(cur.getString(1).equals("Clever"))
        {
            startTimeList.add(cur.getString(0));
            cur.moveToNext();
        }
        else
        {
            cur.moveToNext();
        }
        if(startTimeList.size() == 2)
        {
            return;
        }
    }
ArrayList startTimeList=new ArrayList();
cur=dbAdapter.rawQuery(“选择日期,按日期说明从用户订单中键入”,null);
cur.moveToFirst();
如果(cur.getCount()>0)
{
int i=0;
while(cur.isAfterLast()==false)
{
if(cur.getString(1.equals)(“聪明”))
{
startTimeList.add(cur.getString(0));
cur.moveToNext();
}
其他的
{
cur.moveToNext();
}
if(startTimeList.size()=2)
{
返回;
}
}
但是,对于类型为“聪明的”的连续行,这并没有为我提供日期

在此之后,在您的示例中,DateOfLastCleverReceidedByAduplicate是“2013-05-27T21:45:46.127Z”

String dateOfLastCleverPrecededByADuplicate;

cur = dbAdapter.rawQuery("select Date, Type from User ORDER BY Date DESC", null);

cur.moveToFirst();
String prevType;
String prevDate;
while (!cur.isAfterLast())
{
    if (cur.getString(1) != null &&
        cur.getString(1).equals(prevType) &&
        cur.getString(1).equals("Clever"))
    {
        // found consecutives record with identical type 'Clever'
        dateOfLastCleverPrecededByADuplicate = prevDate;
        break;
    }

    prevDate = cur.getString(0);
    prevType = cur.getString(1);
    cur.moveToNext();
}