如何测试 SQL 中每个组中列值的顺序(基于时间戳)?

How do I test the sequence of values of a column (based on timestamps) within each group in SQL?

我在表 A 中有 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 查询相同的

如果我没理解错的话,你可以用group byhaving:

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
      . . .