Database: Select last non-null entries

前端 未结 4 1096
你的背包
你的背包 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:29

    list of relevant timestamps:

    select max timestamp from part_changes where x_POS is not null group by part
    

    You can make this a view: lets call this view1

    SELECT part_changes.part, part_changes.x-pos 
    FROM part_changes left join view1 on part_changes.part = view1.part
    WHERE x-pos IS NOT NULL 
     AND part_changes.timestamp = view1.timestamp 
    GROUP BY part_changes.part
    

    See where I am going? That should give you the full list for x-pos.

提交回复
热议问题