如何编写SELECT DISTINCT查询?

时间:2017-08-28 14:48:45

标签: sql sql-server reporting-services

我有一个类别列表,我可以使用选择不同的语句,但努力计算''使用类别的次数,我有一个名为Description的列,我需要创建另一个名为occurrence的列。

Description
-------------
Arts, crafts, and collectibles
Baby
Beauty and fragrances
Books and magazines
Business to business
Clothing, accessories, and shoes
Computers, accessories, and services
Education
Electronics and telecom
Entertainment and media
Financial services and products
Food retail and service
Gifts and flowers
Government
Health and personal care
Home and garden
Nonprofit
Pets and animals
Religion and spirituality (for profit)
Retail (not elsewhere classified)
Services - other
Sports and outdoors
Toys and hobbies
Travel
Vehicle sales
Vehicle service and accessories
Books and magazines
Business to business
Clothing, accessories, and shoes
Computers, accessories, and services
Education
Electronics and telecom
Entertainment and media
Financial services and products
Food retail and service
Gifts and flowers
Government
Health and personal care
Services - other
Sports and outdoors
Toys and hobbies
Travel
Vehicle sales
Vehicle service and accessories
Books and magazines
Business to business
Clothing, accessories, and shoes
Business to business
Clothing, accessories, and shoes
Computers, accessories, and services
Education
Electronics and telecom
Entertainment and media
Financial services and products
Food retail and service

1 个答案:

答案 0 :(得分:3)

这听起来像是一个简单的聚合。

Select
   [Description]
   ,Occurences = Count([Description])
From
   YourTable
Group By
   [Description]