In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Follow the previous article
Http://blog.itpub.net/29254281/viewspace-2150229/
After thinking about the algorithm for a day and a half, the algorithm finally got the correct result last night.
In my environment, it takes 90 seconds and there is room for further optimization.
The preferred way is to generate T1 and T2.
The previous use of create table resulted in incorrect types
Because it is a temporary table, you can create the table structure in advance
CREATE TABLE `t1` (
`roomid` int (11) NOT NULL DEFAULT'0'
`userid`bigint (20) NOT NULL DEFAULT'0'
`s` timestamp
`e` timestamp
Primary KEY (`roomid`, `userid`, `s`, `e`)
KEY (`roomid`, `s`, `e`)
)
CREATE TABLE `t2` (
`roomid` int (11) NOT NULL DEFAULT'0'
`userid`bigint (20) NOT NULL DEFAULT'0'
`s` timestamp
`e` timestamp
Primary KEY (`roomid`, `userid`, `s`, `e`)
KEY (`roomid`, `s`, `e`)
)
The first step in the previous article can be encapsulated as a process
DELIMITER $$CREATE DEFINER= `root` @ `localhost`localhost` PROCEDURE `p` () BEGINinsert into t1select distinctroomid,userid,if (date (s)! = date (e) and id > 1 mai date (s+interval id-1 date (s+interval id-1 date (e), e date dated format (s+interval id-1'% localhost` Y-%m-%d 2359VR 59v 59') efrom (SELECT DISTINCT s.roomid, s.userid, s.s, (SELECT MIN (e) FROM (SELECT DISTINCT roomid,userid) Roomend AS eFROM u_room_log aWHERE NOT EXISTS (SELECT * FROM u_room_log bWHERE a.roomid = b.roomidAND a.userid = b.useridAND a.roomend > = b.roomstartAND a.roomend
< b.roomend)) s2WHERE s2.e >S.sAND s.roomid = s2.roomidAND s.userid = s2.userid) AS eFROM (SELECT DISTINCT roomid, userid, roomstart AS sFROM u_room_log aWHERE NOT EXISTS (SELECT * FROM u_room_log bWHERE a.roomid = b.roomidAND a.userid = b.useridAND a.roomstart > b.roomstartAND a.roomstart = b.roomstartAND a.roomend < b.roomend)) eWHERE s.roomid = e.roomidAND s.userid = e.userid) T1, numswhere nums.id=pTime and v2.s
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.