scene : A waybill , If you can stock in multiple times , There will be logs of multiple warehousing records

demand : Now you need to get the latest log of the warehousing record

<>1, stay WHERE Mode of using subquery after condition

* In that case , These conditions can be directly placed in the sub query , And then accurately return the specified latest id, Used in the outer layer id Filter out a piece of data
* If it is id Self accretion , Just use it MAX(id), If not id Self accretion , Then you need to use MAX(create_time) And other fields to get the latest record SELECT *
FROM tms_waybill_log log WHERE = ( SELECT MAX(id) FROM tms_waybill_log
WHERE dr = 0 AND waybill_id = 125 AND waybill_status = 1010 )
<>2, use ORDER BY Mode of

* use ORDER BY Sort them in reverse order , Then take out the first one , It's the latest
* use ORDER BY Hour , Will execute first WHERE
, Filter out some data , Then sort these data , If there is more filtered data , Then the efficiency is relatively low , If the filtered data is relatively small , Then it's almost no effect , Very efficient SELECT *
FROM tms_waybill_log log WHERE log.dr = 0 AND log.waybill_id = 125 AND log.
waybill_status= 1010 ORDER BY DESC LIMIT 1
If there are other methods , Welcome to leave a message at the bottom !

©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?