我想知道八月每个日期的平均数据数量。
例子
31-08 - 2 registers
30-08 - 3 registers
我尝试了以下查询,但没有成功
SELECT AVG(ROW_NUMBER() over (order by Chave_ID desc)), DATEPART(day, datahora)
from San_Chave
where DATEPART(month, datahora) = 8
group by DATEPART(day, datahora), Chave_ID
order by DATEPART(day, datahora) desc
DataHora 是DateTime
类型,而 Chave_Id 是Primary Key
,但数字不是按逻辑顺序排列的,所以我尝试使用ROW_NUMBER()
函数
有人可以帮助我吗?
我想要的输出
MONTH DAY REGISTER
8 31 10
8 30 9
8 29 1
桌子
要进行查询,我认为只需要Chave_Id
and DataHora
,Chave_id
将是寄存器的数量
CREATE TABLE [dbo].[San_Chave](
[Chave_Id] [int] IDENTITY(1,1) NOT NULL,
[Usuario_Id] [int] NULL,
[Credenciada_Id] [int] NULL,
[Usuario_Id_Responsavel] [int] NULL,
[DataHora] [datetime] NULL,
[Transacao] [int] NULL,
[Cliente_Id] [int] NULL,
[DataHoraPegou] [datetime] NULL,
[DataHoraDevolverPrevisao] [datetime] NULL,
[DataHoraEntregou] [datetime] NULL,
[HorasDevolucao] [int] NULL,
[NomeResponsavel] [varchar](130) NULL,
[CpfResponsavel] [varchar](20) NULL,
[RgResponsavel] [varchar](20) NULL,
[TelResponsavel] [varchar](15) NULL,
[Tel2Responsavel] [varchar](15) NULL,
[Endereco] [varchar](300) NULL,
[Devolvido] [bit] NULL,
[TextoDevolucao] [varchar](5000) NULL,
[De] [int] NULL,
CONSTRAINT [PK_San_Chave] PRIMARY KEY CLUSTERED
(
[Chave_Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO