简体   繁体   中英

sql join Query the database ,There is no desired result,

my demand is:from database query newest data,according to time field as a standard,query alarmtime this field ,but alarmtime < time executive sql:

SELECT
    c.entryTime AS alarmtime ,
    a.time AS time
FROM (
    SELECT
        t.DB33,
        MAX( t.Time ) AS time,
        t.Stream,
        t.Coil,
        t.`View` 
    FROM ( 
        SELECT DB33, Time, Stream, Coil, `View` 
        FROM running_check 
        ORDER BY id DESC 
        LIMIT 1000 ) as t 
    GROUP BY t.DB33 ) AS a
LEFT JOIN (
    select cameraID,cameraName 
    from monitor_link_info) as b ON a.db33 = b.cameraID
LEFT JOIN ( 
    SELECT entryTime, cameraID 
    FROM result_video_v2 
    ORDER BY id DESC 
    limit 1000 ) AS c ON a.db33 = c.cameraId 
GROUP BY a.db33, b.cameraName 
ORDER BY a.time DESC, alarmtime DESC

execute result is unamiable,please look at image now time column not what i want,Because he didn't change.

在此处输入图片说明

SELECT
    c.entryTime AS alarmtime ,
    a.time AS TIME

    FROM 
    ( 
        SELECT DB33, MAX(TIME) TIME, Stream, Coil, `View` 
        FROM running_check 
        ORDER BY id DESC 
        GROUP BY t.DB33
        LIMIT 1000 
    ) AS a 

    LEFT JOIN 
    (
        SELECT cameraID,cameraName 
        FROM monitor_link_info
        GROUP BY cameraID
        LIMIT 1000
    ) AS b ON (a.db33 = b.cameraID)
    LEFT JOIN ( 
        SELECT entryTime, cameraID 
        FROM result_video_v2 
        GROUP BY cameraID
        ORDER BY id DESC
        LIMIT 1000
    ) AS c ON (a.db33 = c.cameraID) 

GROUP BY a.db33, b.cameraName 
ORDER BY a.time DESC, c.entryTime DESC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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