1

我有一张看起来像这样的表格(真正的表格有日期和时间代替字母):

| 分配 | 开始 | 结尾
| xyz | 一个 | 乙     
| xyz | 乙| C     
| xyz | C | D     
| xyz | D | 乙     
| xyz | E | F    
| fgh | 一个 | 乙
| fgh | 乙| C

等等

每个分配的代码(xyz,fgh 等)都有一个轮换,其中“结束”与下一个“开始”一致,直到一个指示定义结束的值(此处为“F”)。

我正在寻找一个扫描/验证这种旋转确实发生的语句,它从 A 开始并以 F 结束,并且在此之前完成了每一步。

任何帮助是极大的赞赏。

编辑:旋转总是使用 5 行(或 4 步),即使间隔长度可以在两者之间改变。

4

1 回答 1

0

这确实是一种有效的技巧,因为日期被字符替换,但它可能会给您提供如何使其真正起作用的想法。

select * from (
  select a_code, min(a_start) as thestart, max(a_end) as theend,
       substring(group_concat(a_start order by a_start), 3) as starts, 
       substring(group_concat(a_end order by a_end), 1, length(group_concat(a_end))-2) as  ends
  from so_test
  group by a_code ) as grpSelect
where thestart = 'a'
and theend = 'f'
and starts = ends

xyz 的 a_start 的 group_concat 产生一个字符串 'a,b,c,d,e',而 a_end 的 group_concat 产生 b,c,d,e,f。子字符串从开头删除 a 并从末尾删除 f,以便外部查询可以比较两个字符串中的 b、c、d、e。

于 2013-11-14T21:00:18.120 回答