我有一个像这个例子的 MYSQL 表:
[ID]--[Date]--[UserID]--[Username]--[String]
1 12-10-06 02:35:01 25 Jack string1
2 12-10-06 02:38:01 25 Jack string2
3 12-10-06 02:40:01 25 Jack END
4 12-10-06 02:42:01 36 Jill string1
5 12-10-06 02:45:01 36 Jill string2
6 12-10-06 02:48:01 36 Jill END
7 12-10-06 02:50:01 25 Jack string1
8 12-10-06 02:52:01 25 Jack string2
9 12-10-06 02:55:01 25 Jack END
我正在使用这个 MYSQL 查询对它们进行分组:
SELECT m1.Date, m1.Username, m1.UserID
FROM Username m1 LEFT JOIN Username m2
ON (m1.UserID = m2.UserID AND m1.ID < m2.ID)
WHERE m2.ID IS NULL
ORDER BY Date DESC
它可以工作,但这个查询的问题是它只给出每个用户的最后一个条目作为输出:
6 12-10-06 02:48:01 36 Jill
9 12-10-06 02:55:01 25 Jack
我想将所有会话作为输出,例如:
12-10-06 02:35:01 - 12-10-06 02:40:01 25 Jack
12-10-06 02:42:01 - 12-10-06 02:48:01 25 Jill
12-10-06 02:50:01 - 12-10-06 02:55:01 25 Jack
我怎样才能用 PHP 和 MYSQL 做到这一点?