0

我在 tableA 中有 colA、colB、colC,其中 colC 是时间戳变量。

colB 有 5 个可能的值。

select distinct(colB) from tableA; 

x
y
z

我想确保对于 colA 的每个值,colB='a' 的记录比 colB='b' 的记录具有更早的时间戳,依此类推。因此,对于 colA 的每个值,colB='b' 记录应该在 colB='a' 之后,而 colB='c' 记录应该在 colB='b' 之后

我需要一个相同的 SQL 查询

4

1 回答 1

1

如果我理解正确,您可以使用group byand having

select cola
from tableA
group by cola
having max(case when colb = 'a' then timestamp end) < min(case when colb = 'b' then timestamp end) and
       max(case when colb = 'b' then timestamp end) < min(case when colb = 'c' then timestamp end) and
      . . .
于 2018-03-12T17:34:45.487 回答