SQL Server: how to calculate median (group by)? [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Function to Calculate Median in Sql Server I have a table like this: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[cars]( [id] [int] IDENTITY(1,1) NOT NULL, [sp] [int] NOT NULL, [dst] [int] NOT NULL, [type] [varchar](10) NULL, CONSTRAINT [PK_id] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW