SQL to find the first occurrence of sets of data in a table

前端 未结 4 1438
执念已碎
执念已碎 2021-02-09 14:48

Say if I have a table:

CREATE TABLE T
(
    TableDTM  TIMESTAMP  NOT NULL,
    Code      INT        NOT NULL
);

And I insert some rows:

4条回答
  •  感情败类
    2021-02-09 15:10

    could you try something like

    "SELECT DISTINCT Code, (SELECT MIN(TableDTM) FROM T AS Q WHERE Q.Code = T.Code) As TableDTM FROM T;"
    

    and if you need to exclude the 0, change it in:

     SELECT DISTINCT Code, (SELECT MIN(TableDTM) FROM T AS Q WHERE Q.Code = T.Code) As TableDTM FROM T WHERE Code <> 0;
    

提交回复
热议问题