我有一个表member_track,用于跟踪成员的网站访问量。从它的外观来看,它跟踪每一个负载。
我需要从每个成员生成最新访问的结果集。
以下是数据样本:
member_id last_accessed 1413 2015-5-26 8:57 1413 2015-5-26 8:54 1413 2015-5-26 8:50 1413 2015-5-26 8:48 1413 2015-5-26 8:20 1413 2015-5-26 8:17 1412 2015-4-30 7:34 1412 2015-4-30 7:33 1411 2015-4-18 15:51 1411 2015-4-18 15:50
输出必须是:
member_id last_accessed 1413 2015-5-26 8:57 1412 2015-4-30 7:34 1411 2015-4-18 15:51
(last_accessed
是datetime
字段)
我已尝试过group by和max的各种事情,但没有取得任何成功。我该怎么做呢?
答案 0 :(得分:2)
您只需要max(last_accessed)
按member_id
查询SELECT member_id, max(last_accessed)
FROM member_track
GROUP BY member_id
:
public static void notify(String s)
{
m_instance.setNote(s);
int duration = Toast.LENGTH_SHORT;
m_instance.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(m_instance, m_instance.getNote(), Toast.LENGTH_SHORT).show();
Log.i(QtApplication.QtTAG,"run run Toast.makeText");
}
});
}
答案 1 :(得分:1)
您可以尝试以下查询。
SELECT member_id,last_accessed
FROM member_track
WHERE last_accessed in(
SELECT Max(last_accessed)
FROM member_track
GROUP BY member_id)