我想在自定义范围内选择 [price] 字段值的出现次数:
我的价格范围是:
< 10
10-20
20-50
> 50
因此,如果价格为 3、4、11 和 20,则结果将是:
< 10 (2)
10-20 (1)
21-50 (1)
> 50 (0)
这是表定义:
CREATE TABLE [dbo].[products](
[id] [int] IDENTITY(1,1) NOT NULL,
[price] [decimal](8, 0) NULL,
[createdate] [datetime] NOT NULL,
CONSTRAINT [PK_products] PRIMARY KEY CLUSTERED
(
[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
ALTER TABLE [dbo].[products] ADD CONSTRAINT [DF_products_createdate] DEFAULT (getdate()) FOR [createdate]
GO