In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Order:sn
Procedures:sn,status
1. There are order table and flow table.
The order table contains the details of the order [assuming there is no order status], and each order has a variety of states: paid, in process, pending receipt, and so on. The current demand may be to query the order status of all orders that are waiting to be received.
[answer] first find all the orders whose latest status is to be received, then make a left join with the order form, and you can get it.
First, look for all orders whose latest status is waiting to be received.
Originally patted the head to think that group by order by took the first one, and then tried it, and found that what group by got back is not the latest status, but the first one after the grouping. This is because the execution order of statements in MySQL is to execute group by first and then order by. Obviously, it's impossible to get the latest one. We can find out the latest status of each order in this way.
Select sn,max (status) from procedures group by sn.
The correct thing is to write it in the following way: do a join with yourself, and finally with order join.
SELECT a.id, a.sn, a.createdpaper.type FROM (SELECT sn, max (created_at) created_at FROM procedures GROUP BY sn) b JOIN procedures an ON a.sn = b.sn AND a.created_at = b.created_at where a.type=11
Select c. Writing journal tmp.type from complaints as c right join (
SELECT a.id, a.sn, a.createdpaper.type FROM (SELECT sn, max (created_at) created_at FROM procedures GROUP BY sn) b JOIN procedures an ON a.sn = b.sn AND a.created_at = b.created_at where a.type=11
) as tmp on tmp.sn=c.sn
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.