简体   繁体   English

选择mysql中没有自动增量的最后一行

[英]select last row in mysql with no-auto incremental

I'm trying to make a temp logging database. 我正在尝试建立一个临时日志记录数据库。 Still on the learnig level. 仍处于学习水平。

How do I get the last row from the database? 如何从数据库中获取最后一行?

select * from tempdat order by tdate desc limit 1 

gives the first entry of the day but I want the last. 给出当天的第一条记录,但我想要最后一条。 See below, it could return the entry whit time 21:25:03 如下所示,它可能会返回输入21:25:03时间21:25:03

+------------+----------+------+-------------+
| 2014-03-29 | 21:20:02 | inne |      22.875 |
| 2014-03-29 | 21:25:03 | inne |      22.875 |
+------------+----------+------+-------------+
1933 rows in set (0.16 sec)

mysql> select * from tempdat order by tdate desc limit 1;

+------------+----------+------+-------------+
| tdate      | ttime    | zone | temperature |
+------------+----------+------+-------------+
| 2014-03-29 | 00:00:03 | inne |      21.250 |
+------------+----------+------+-------------+
1 row in set (0.03 sec)

Just use two criteria for ordering: first tdate , then ttime . 只需使用两个条件进行排序:首先是tdate ,然后是ttime For example: 例如:

    SELECT * 
      FROM tempdat 
  ORDER BY tdate DESC, ttime DESC 
     LIMIT 1;

Note that order direction should be specified after each column used. 请注意,应在使用的每一列之后指定顺序方向。 ORDER BY tdate, ttime DESC will first order all the records by tdate ASC . ORDER BY tdate, ttime DESC将首先按tdate ASC所有记录进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM