取出datetime中的日期信息以下摘自 MySQL 5.1 Reference Manual DATE(expr)
Extracts the date part of the date or datetime expression expr. mysql> SELECT DATE('2003-12-31 01:02:03'); -> '2003-12-31'[align=center]====思想重于技巧==== [/align]
select 用户名,IP,时间 from 用户登录日志 as l where 时间=(select min(时间) from 用户登录日志 where 用户名=l.用户名 and DATE(时间)=DATE(.时间))[align=center]====思想重于技巧==== [/align]
select 用户名,IP,时间 from 用户登录日志 as l where 时间=(select min(时间) from 用户登录日志 where 用户名=l.用户名 and DATE(时间)=DATE(l.时间))少了个l[align=center]====思想重于技巧==== [/align]
select a.用户名,a.IP,a.时间 from 用户登录日志 as a inner join (select 用户名,DATE(时间) as dDay,min(时间) as minTime from 用户登录日志 group by 用户名,DATE(时间)) as b on a.用户名=b.用户名 and a.时间=b.minTime[align=center]====思想重于技巧==== [/align]
DATE(expr)
Extracts the date part of the date or datetime expression expr. mysql> SELECT DATE('2003-12-31 01:02:03');
-> '2003-12-31'[align=center]==== 思想重于技巧 ====
[/align]
from 用户登录日志 as l
where 时间=(select min(时间) from 用户登录日志 where 用户名=l.用户名 and DATE(时间)=DATE(.时间))[align=center]==== 思想重于技巧 ====
[/align]
from 用户登录日志 as l
where 时间=(select min(时间) from 用户登录日志 where 用户名=l.用户名 and DATE(时间)=DATE(l.时间))少了个l[align=center]==== 思想重于技巧 ====
[/align]
from 用户登录日志 as a inner join
(select 用户名,DATE(时间) as dDay,min(时间) as minTime from 用户登录日志 group by 用户名,DATE(时间)) as b
on a.用户名=b.用户名 and a.时间=b.minTime[align=center]==== 思想重于技巧 ====
[/align]