How do I use T-SQL Group By

后端 未结 5 1511
星月不相逢
星月不相逢 2020-12-06 04:17

I know I need to have (although I don\'t know why) a GROUP BY clause on the end of a SQL query that uses any aggregate functions like count,

5条回答
  •  感情败类
    2020-12-06 04:44

    Counting the number of times tags are used might be a google example:

    SELECT TagName, Count(*)
    AS TimesUsed
    FROM Tags
    GROUP BY TagName ORDER TimesUsed
    

    If you simply want a distinct value of tags, I would prefer to use the DISTINCT statement.

    SELECT DISTINCT TagName
    FROM Tags
    ORDER BY TagName ASC
    

提交回复
热议问题