2017-08-28 78 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