我有一张表table1
,如下所示。我想查找H
字段中位于两个Status
之间的所有L
。上述标准的输出应为04/01/15
,05/01/15
和07/01/15
。我该如何解决这个问题?
Date Status
01/01/15 A
02/01/15 H
03/01/15 L
04/01/15 H
05/01/15 H
06/01/15 L
07/01/15 H
08/01/15 L
答案 0 :(得分:0)
我认为你可以使用这样的查询:
SELECT
t.Date, t.Status
FROM
yourTable AS t
JOIN (
SELECT MIN(Date) AS minDate, Max(Date) AS maxDate
FROM yourTable
WHERE Status = 'L') AS l
ON t.Date >= l.minDate
AND t.Date <= l.maxDate
AND t.Status <> 'L';