2017-08-28 82 views
-5

我有一个类别列表,我能够使用选择不同的语句,但努力“计数”一个类别被使用了多少次,我有一个名为Description的列,我需要创建另一个名为occurrence的列。如何编写SELECT DISTINCT查询?

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 
+3

阅读本请https://stackoverflow.com/help/how-to-ask –

+1

可以使用计数的'组合(1)'和'组by' – Hackerman

+0

向我们展示您的查询,准确地解释为什么输出不是你想要的,为什么你认为你的查询会产生它。 – csmckelvey

回答

3

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

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

这是行不通的,感谢您的协助 – AfricanHeart

+6

那么,它会做就是你问的问题。也许你问的不是你需要的。为什么它不起作用? – scsimon

+0

这很酷,我不知道你可以做'别名= COUNT(列)'。与COUNT(列)作为别名相反,做同等操作有区别吗? – Simon