<select id="getUserVisitDoListDistinct" parameterClass="java.util.Map" resultMap="userVisitDoResult">
SELECT
id,
user_id_to,
user_id_from,
status,
MAX(createtime) AS createtime
FROM
(select * from dx_user_visit ORDER BY createtime DESC) AS foo
WHERE user_id_to = #user_id_to# AND user_id_from != #user_id_to#
GROUP BY (DATE_FORMAT(createtime,"%Y%m%d")),user_id_from
<isGreaterThan prepend="HAVING" property="lastId" compareValue="0">
<![CDATA[
id < #lastId#
]]>
</isGreaterThan>
ORDER BY createtime DESC
LIMIT 0,#count#
</select>
额,我已经解决了,贴给大家看一看,关键是同时ORDER BY日期和人,写完了发现还是很简单的...
从访问中选择 v1.* 作为 v1
右连接(
按 id 从访问组中选择 id, max(createtime) 作为 ctime
)作为 v1.id=v2.id 和 v1 上的 v2 .createtime=v2.ctime
从访问中选择 v1.* 作为 v1
右连接(
从访问中选择 vv1.id, max(vv1.createtime) 作为 ctime 作为 vv1
内部连接在 vv1.DATE_FORMAT 上作为 vv2 访问( createtime,"%Y%m%d")=vv2..DATE_FORMAT(createtime,"%Y%m%d")
group by vv1.id
) as v2 on v1.id=v2.id和 v1.createtime=v2.ctime
select user_id_from, min(createtime) last_visit_time from tablename group by user_id_from order by last_visit_time limit num;
select max time from tb group by usrid这样如何