Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 按句点的sql查询_Sql Server_Sql Server 2005 - Fatal编程技术网

Sql server 按句点的sql查询

Sql server 按句点的sql查询,sql-server,sql-server-2005,Sql Server,Sql Server 2005,我的表中有两个字段,NEXTTIME和ENDTIME,表名是VISIT 我将从我的页面中得到一个值,它是00:05:00或类似的值。最少5分钟 我必须根据该值从数据库中进行查询 我将得到最早的下一个时间和该时间+00:05:00 假设下一次最早的时间是06:44 我的查询将是06:45、06:50,依此类推 我还将有另一个输入值,即间隔时间 我知道 我只想知道如何按时间间隔获取查询 结果是这样的。 下一时间:结束时间 06:55:00~06:58:00 07:25:00~07:28:00 07

我的表中有两个字段,NEXTTIME和ENDTIME,表名是VISIT

我将从我的页面中得到一个值,它是00:05:00或类似的值。最少5分钟

我必须根据该值从数据库中进行查询

我将得到最早的下一个时间和该时间+00:05:00

假设下一次最早的时间是06:44

我的查询将是06:45、06:50,依此类推

我还将有另一个输入值,即间隔时间

我知道

我只想知道如何按时间间隔获取查询

结果是这样的。

下一时间:结束时间

06:55:00~06:58:00

07:25:00~07:28:00

07:35:00~08:52:00

08:38:00~08:48:00

08:40:00~08:54:00

08:43:00~09:36:00


09:12:00~09:30:00

根据提供的信息和我对您问题的理解,我提出了解决方案。为了满足图表周期的要求,只需更改每个联合查询的select语句和where子句中的周期

USE master
GO

create database Tests
GO

USE Tests
GO

create table Visits (
    nexttime    datetime    not null
    , endtime   datetime    not null
)
GO

BEGIN TRANSACTION

insert into Visits (nexttime, endtime) select N'06:55:00', N'06:58:00'
insert into Visits (nexttime, endtime) select N'07:25:00', N'07:28:00'
insert into Visits (nexttime, endtime) select N'07:35:00', N'08:52:00'
insert into Visits (nexttime, endtime) select N'08:38:00', N'08:48:00'
insert into Visits (nexttime, endtime) select N'08:40:00', N'08:54:00'
insert into Visits (nexttime, endtime) select N'08:43:00', N'09:36:00'
insert into Visits (nexttime, endtime) select N'09:12:00', N'09:30:00'

COMMIT

select N'06:30 - 07:00' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'06:30:00', 108) and CONVERT(datetime, N'07:00:00', 108)
union
select N'07:00 - 07:30' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'07:00:00', 108) and CONVERT(datetime, N'07:30:00', 108)
union
select N'07:30 - 08:00' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'07:30:00', 108) and CONVERT(datetime, N'08:00:00', 108)
union
select N'08:00 - 08:30' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'08:00:00', 108) and CONVERT(datetime, N'08:30:00', 108)
union
select N'08:30 - 09:00' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'08:30:00', 108) and CONVERT(datetime, N'09:00:00', 108)
union
select N'09:00 - 09:30' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'09:00:00', 108) and CONVERT(datetime, N'09:30:00', 108)
输出

╔══════════════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║06:30 - 07:00 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║07:00 - 07:30 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║07:30 - 08:00 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║08:00 - 08:30 ║   ║   ║   ║   ║   ║   ║   ║   ║   ║   ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║08:30 - 09:00 ║ 1 ║ 2 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║09:00 - 09:30 ║ 0 ║ 0 ║ 1 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╚══════════════╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝

请随时说明我是否正确理解了您的问题。

以下是基于提供的信息和我对您问题的理解,以及我提出的解决方案。为了满足图表周期的要求,只需更改每个联合查询的select语句和where子句中的周期

USE master
GO

create database Tests
GO

USE Tests
GO

create table Visits (
    nexttime    datetime    not null
    , endtime   datetime    not null
)
GO

BEGIN TRANSACTION

insert into Visits (nexttime, endtime) select N'06:55:00', N'06:58:00'
insert into Visits (nexttime, endtime) select N'07:25:00', N'07:28:00'
insert into Visits (nexttime, endtime) select N'07:35:00', N'08:52:00'
insert into Visits (nexttime, endtime) select N'08:38:00', N'08:48:00'
insert into Visits (nexttime, endtime) select N'08:40:00', N'08:54:00'
insert into Visits (nexttime, endtime) select N'08:43:00', N'09:36:00'
insert into Visits (nexttime, endtime) select N'09:12:00', N'09:30:00'

COMMIT

select N'06:30 - 07:00' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'06:30:00', 108) and CONVERT(datetime, N'07:00:00', 108)
union
select N'07:00 - 07:30' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'07:00:00', 108) and CONVERT(datetime, N'07:30:00', 108)
union
select N'07:30 - 08:00' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'07:30:00', 108) and CONVERT(datetime, N'08:00:00', 108)
union
select N'08:00 - 08:30' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'08:00:00', 108) and CONVERT(datetime, N'08:30:00', 108)
union
select N'08:30 - 09:00' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'08:30:00', 108) and CONVERT(datetime, N'09:00:00', 108)
union
select N'09:00 - 09:30' as period
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 5 and 10 then 1 else 0 end) as [5:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 10 and 15 then 1 else 0 end) as [10:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 15 and 20 then 1 else 0 end) as [15:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 20 and 25 then 1 else 0 end) as [20:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 25 and 30 then 1 else 0 end) as [25:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 30 and 35 then 1 else 0 end) as [30:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 35 and 40 then 1 else 0 end) as [35:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 40 and 45 then 1 else 0 end) as [40:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) between 45 and 50 then 1 else 0 end) as [45:00]
    , SUM(case when DATEDIFF(MI, nexttime, endtime) >= 50 then 1 else 0 end) as [50:00] 
from Visits
where nexttime between CONVERT(datetime, N'09:00:00', 108) and CONVERT(datetime, N'09:30:00', 108)
输出

╔══════════════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║06:30 - 07:00 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║07:00 - 07:30 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║07:30 - 08:00 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║08:00 - 08:30 ║   ║   ║   ║   ║   ║   ║   ║   ║   ║   ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║08:30 - 09:00 ║ 1 ║ 2 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1 ║
╠══════════════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║09:00 - 09:30 ║ 0 ║ 0 ║ 1 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╚══════════════╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝


请随意说明我是否正确理解了您的问题。

那么,您希望半小时为行,五分钟为列?对于每一列,你想要这5分钟的访问次数,对吗?你能提供样本数据,以便我们大家可以根据本地测试数据库测试一些查询吗?我已经用样本数据编辑了这个问题。你的表中没有任何Id吗?我现在没有时间来处理这个问题。如果你建立一个周期和间隔表作为一对工作表,你可以通过一个pivot来完成这项工作。]这应该能让你顺利完成。那么,你希望半小时是行,五分钟是列?对于每一列,你想要这5分钟的访问次数,对吗?你能提供样本数据,以便我们大家可以根据本地测试数据库测试一些查询吗?我已经用样本数据编辑了这个问题。你的表中没有任何Id吗?我现在没有时间来处理这个问题。如果你建立一个周期和间隔表作为一对工作表,你可以用一个轴来完成这项工作。]希望你能继续下去。那太好了。。但是,正如我所说。。周期和间隔时间是可变的。用户将在5分钟或15分钟内输入这两个值。我们必须进行相应的计算。
between
子句中的值是可变的。只要设置参数,就可以了。这符合要求吗?有点。。但是我真正需要的是。。比如说8点到10点。如果时段时间是0:30,则有B4行,如果是0:15,则有B8行,依此类推。然后,您需要创建一个以所需间隔作为输入参数的存储过程,然后使用工作表根据输入参数值插入行,以便表示您的时段,然后根据时间间隔更新此表。太好了。。但是,正如我所说。。周期和间隔时间是可变的。用户将在5分钟或15分钟内输入这两个值。我们必须进行相应的计算。
between
子句中的值是可变的。只要设置参数,就可以了。这符合要求吗?有点。。但是我真正需要的是。。比如说8点到10点。如果时段时间是0:30,则有B4行,如果是0:15,则有B8行,依此类推。然后,您需要创建一个以所需间隔作为输入参数的存储过程,然后使用工作表根据输入参数值插入行,以便表示您的时段,然后根据时间间隔更新此表。