当前位置:   article > 正文

mysql:最新的一条记录、最大值(max)和最小值(min)针对字符串的取值不对_mysql. min 和max 反了

mysql. min 和max 反了

直接贴代码:(领悟看个人QAQ)

百度搜的,但是怕忘记。

一张表获取最新的一条记录:

  1. -- 方法1
  2. select a.*
  3. from table1 a
  4. where not exists(select 1
  5. from table1 b
  6. where b.name=a.name and b.gdtime>a.gdtime)
  7. -- 方法2
  8. select a.*
  9. from table1 a
  10. inner join
  11. (select name,
  12. max(gdtime) 'maxgdtime'
  13. from table1
  14. group by name) b on a.name=b.name and a.gdtime=b.maxgdtime

mysql中最大值< max(col) > 与最小值< min(col) >针对字符串的取值不对:

select min(col * 1) , max(col * 1) from table;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/952702
推荐阅读
相关标签
  

闽ICP备14008679号