Database: Select last non-null entries

前端 未结 4 1097
你的背包
你的背包 2021-02-19 11:47

Here\'s a question I\'ve been racking my brain over. Let\'s say I have a table that has a series of timestamps and a part number as the primary key. The table stores incremental

4条回答
  •  野性不改
    2021-02-19 12:20

    For only one part this should give you an answer .. thanks to ruakh

    But I dont like this version ..

    SELECT 
        (SELECT timestamp  FROM part_changes WHERE part = $part 
        ORDER BY timestamp DESC
        LIMIT 1) as timestamp,
    
        (SELECT x-pos FROM part_changes WHERE part = $part and x-pos IS NOT NULL
        ORDER BY timestamp DESC
        LIMIT 1) as xpos,
    
        (SELECT y-pos FROM part_changes WHERE part = $part and  y-pos IS NOT NULL
        ORDER BY timestamp DESC
        LIMIT 1) as ypos,
    
        (SELECT status FROM part_changes WHERE part = $part and status IS NOT NULL
        ORDER BY timestamp DESC
        LIMIT 1)) as status
    

提交回复
热议问题