title: Misuse of aggregate function MAX()
body: <p>I want <strong>latest not null</strong> value of column <code>ignition_status</code> in Alert table. </p>
  
  <p>I have column <code>unix_time</code> which is time in Unix Time Stamp, so max the <code>unix_time</code> column value, latest is the entry.</p>
  
  <p><strong>Below is my code</strong> </p>
  
  <pre><code>cursor = dbUtilsObj.query(Alert.TABLE_NAME, new String[] { alertType_COLUMN }, " MAX(" + Alert.Columns.KEY_ALERT_UNIX_TIME
                  + ")" + AND + Alert.Columns.KEY_MACHINE_TELE_DEVICE_NO + EQUALS + AND + alertType_COLUMN + IS_NOT_NULL,
                  new String[] { String.valueOf(teleDevieNo) }, null, null, Alert.Columns.KEY_ALERT_UNIX_TIME);
  </code></pre>
  
  <p><strong>getting error</strong> </p>
  
  <pre><code>(1) misuse of aggregate function MAX()
  : android.database.sqlite.SQLiteException: misuse of aggregate function MAX() (code 1): , while compiling: SELECT ignition_status FROM alert WHERE  MAX(unix_time) and tele_device_no = ?  and ignition_status IS NOT NULL  ORDER BY unix_time
  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
  at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
  at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
  at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
  at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1420)
  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1267)
  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1138)
  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1306)
  at com.jd.database.DBUtils.query(DBUtils.java:473)
  at com.jd.database.AlertDBUtils.getLatestNotNullValueForType_COLUMN_ByTeleDeviceNo(AlertDBUtils.java:161)
  at com.jd.sms.SMSIntentService.parseE1_VehicleMovemenEvent(SMSIntentService.java:158)
  at com.jd.sms.SMSIntentService.parseMsgAndInputInDb(SMSIntentService.java:122)
  at com.jd.sms.SMSIntentService.processMessage(SMSIntentService.java:97)
  at com.jd.sms.SMSIntentService.procassRequest(SMSIntentService.java:71)
  at com.jd.sms.SMSIntentService.onHandleIntent(SMSIntentService.java:39)
  at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:176)
  at android.os.HandlerThread.run(HandlerThread.java:60)
  android.database.sqlite.SQLiteException: misuse of aggregate function MAX() (code 1): , while compiling: SELECT ignition_status FROM alert WHERE  MAX(unix_time) and tele_device_no = ?  and ignition_status IS NOT NULL  ORDER BY unix_time
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
  </code></pre>
  
  <p>In short I'm trying the query  <code>SELECT ignition_status FROM alert WHERE  MAX(unix_time) and tele_device_no = ?  and ignition_status IS NOT NULL  ORDER BY unix_time</code></p>
  
  <p>So what should go to <code>dbUtilsObj.query()</code> method above?
  At least please tell me the correct raw query.</p>