我有(简化的)数据库表A,它既保存母批纯度值,也保存批处理纯度(所有批次都是从以前的“母批”中生成的)。
我试图弄清楚如何通过SQL提取批纯度,以及批纯度与前一个母批之间的区别。示例名称始终保持不变,但可以是大量批号。
表A
Sample Name | Purity | Date (DD/MMM/YY)
---------------+-----------+-----------------
Mother Batch | 100 |10-Oct-20
Batch 1 | 96 |11-Oct-20
Batch 2 | 94 |13-Oct-20
Mother Batch | 98 |14-Oct-20
Batch 1 | 94 |16-Oct-20
Many thanks
Bob发布于 2020-11-10 13:42:29
使用条件窗口函数:
select t.*,
datediff(date,
max(case when samplename like 'Mother%' then date end) over (order by date)
) as diff
from t;编辑:
在Server中,您将使用:
datediff(day,
max(case when samplename like 'Mother%' then date end) over (order by date),
date
) as diffhttps://stackoverflow.com/questions/64770015
复制相似问题