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语句 

解决方案 »

  1.   

    不是啊、我昨天都写过了,没写出来.在MsSQL是可以运行成功的  我对Mysql运行语法不是很清晰 求讲解
      

  2.   

    看看MYSQL的HELP,你的代码 ?
      

  3.   

    create procedure sp_test()
    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
      

  4.   

    请看清楚问题好不好,存储过程我可以写出来,但是我想要把这个可以在MSsql中执行的语句 改一下 也同样可以在mysql中执行 谢谢 各位大大有什么高招么?
      

  5.   

    请看清楚问题好不好,存储过程我可以写出来,但是我想要把这个可以在MSsql中执行的语句 改一下 也同样可以在mysql中执行 谢谢 各位大大有什么高招么?人家都帮你写好了,你只要把存储过程里面的局部变量改成全局变量,拷出来就可以运行,动下手,查下资料吧,
      

  6.   

    先参考一下MYSQL官方免费手册中的例子亲自写一下吧。如何有具体的问题再把你自己写的代码和错误信息一同贴出,然后大家进行讨论分析。
      

  7.   

    谢谢各位了 我只是想把这个SQL语句写成是T-SQL语句 而不是存储过程(我也会写这个存过).
    想要在命令行中直接执行并返回结果.小弟刚接触MySql语句 有些不懂还请见谅 散分啦。都给你们啦