mysql 求助sql语句

image.png

我需要获取最新的

ActionType和AgentID 这两列数据,且AgentID不是只有一个,这个sql该怎么写?


回音无痕 发布于 2018-11-7 16:47
1min目标场景问卷 立即参与
回答问题
悬赏:5 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
axingLv6专家互助
发布于2018-11-7 18:28(编辑于 2018-11-7 18:33)

是要这个结果不
select ActionType,AgentID from 表名 where id=(select max(id) from 表名)
或者是这个:
select ActionType,AgentID from 表名 where id in (select max(id) from 表名 group by agentID)

  • 回音无痕 回音无痕(提问者) select b.* from ( select max(id) id,agentid from agent_state where date_format(actiontime, \'%Y-%m-%d\')=date_format(now(), \'%Y-%m-%d\') group by agentid)a left join agent_state b on a.id=b.id,改动下
    2018-11-07 18:59 
最佳回答
0
lefantianLv2初级互助
发布于2018-11-7 16:50(编辑于 2018-11-7 17:46)

select a. * from 表名称 a where ActionTime = ( select max (ActionTime) from 表名称 b where b.ActionType  = a.ActionType ) 

最佳回答
0
孤陌Lv6资深互助
发布于2018-11-7 16:57(编辑于 2018-11-7 17:34)

看我最新回答 

select a. * from 表名称 a where AgentID = ( select max (AgentID) from CS where ActionType  = a.ActionType ) order by a.ActionType   那就是这样

image.png

如图 image.pngimage.png

  • 回音无痕 回音无痕(提问者) 重复字段???这个是哪个字段?
    2018-11-07 17:00 
  • 孤陌 孤陌 回复 回音无痕(提问者) ActionType
    2018-11-07 17:05 
  • 孤陌 孤陌 回复 回音无痕(提问者) 可以把时间字段修改成ID字段 我看了一下你ID字段是自增的也是可以比较的
    2018-11-07 17:14 
  • 回音无痕 回音无痕(提问者) 回复 孤陌 警告:com.fr.general.data.TableDataException: 错误代码:1301 数据集配置错误 Query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'table where ActionType=a.ActionType and ActionTime
    2018-11-07 17:17 
  • 孤陌 孤陌 回复 回音无痕(提问者) select a. * from tb a where val = ( select max (val) from tb where name = a.name) order by a.name 这样写 你不是就是想要 拿到ActionType字段分组后 的ID最大值吗?
    2018-11-07 17:19 
  • 4关注人数
  • 726浏览人数
  • 最后回答于:2018-11-7 18:33
    请选择关闭问题的原因
    确定 取消
    返回顶部