declare @k dateTime,
@l int
set @k = (select max(Log_Time) from LoginLogs where user_id=10)
set @l = (select count(*) from LoginLogs where Log_Time >= '2013-08-01 00:00' and Log_Time<='2013-08-31 23:59' and user_id=10 )select Maxtime,Log_Ip,LoginCount from (select max(Log_Time) as Maxtime, Log_Ip ,@l as LoginCount from LoginLogs where user_id=10 and Log_Time=@k
group by Log_Ip union select max(Log_Time)as Maxtime,Log_Ip ,@l as LoginCount from LoginLogs where user_id=10 and Log_Time<@k group by Log_Ip ) as t
order by Maxtime desc这句在MSSQl中是可以运行成功的,请高手改成MySQl语句 不要存储过程,就是一般的Sql语句
begin
declare k dateTime;
declare l int;
select max(Log_Time) into k from LoginLogs where user_id=10 ;
select count(*) into l from LoginLogs where Log_Time >= '2013-08-01 00:00' and Log_Time<='2013-08-31 23:59' and user_id=10;
select Maxtime,Log_Ip,LoginCount from (select max(Log_Time) as Maxtime, Log_Ip ,l as LoginCount from LoginLogs where user_id=10 and Log_Time=k
group by Log_Ip union select max(Log_Time)as Maxtime,Log_Ip ,l as LoginCount from LoginLogs where user_id=10 and Log_Time<k group by Log_Ip ) as t
order by Maxtime desc;
end
想要在命令行中直接执行并返回结果.小弟刚接触MySql语句 有些不懂还请见谅 散分啦。都给你们啦