sql 中基于行数的行之间的差异(SQL 服务器)
Difference between rows in sql based on rows number (SQL Server)
我有问题。我有 table 以下列和示例数据:
RN Date Time
---------------------
1 2015-02-02 12
2 2015-02-02 25
3 2015-02-02 27
1 2015-02-08 42
2 2015-02-08 45
1 2015-03-01 60
2 2015-03-01 62
3 2015-03-01 63
4 2015-03-01 63
我需要获取每天开始时间和结束时间之间的差异。
例如:
27-12
45-42
63-60
有什么建议吗? :)
select
Date, max(Time) as mx, min(Time) as mn, max(Time) - min(Time) as diff
from table_name
group by Date
我有问题。我有 table 以下列和示例数据:
RN Date Time
---------------------
1 2015-02-02 12
2 2015-02-02 25
3 2015-02-02 27
1 2015-02-08 42
2 2015-02-08 45
1 2015-03-01 60
2 2015-03-01 62
3 2015-03-01 63
4 2015-03-01 63
我需要获取每天开始时间和结束时间之间的差异。
例如:
27-12
45-42
63-60
有什么建议吗? :)
select
Date, max(Time) as mx, min(Time) as mn, max(Time) - min(Time) as diff
from table_name
group by Date