Forum Stats

  • 3,770,127 Users
  • 2,253,073 Discussions
  • 7,875,336 Comments

Discussions

Grouping, Sorting, And Counting

User_MMW9K
User_MMW9K Member Posts: 1 Green Ribbon

If you have a list of dates, how do you group by month, and then count the frequency of entries per month for each month?

Tagged:

Answers

  • KayK
    KayK Member Posts: 1,685 Bronze Crown

    Hi MMW,

    welcome to the communities.

    Do you look for something like this ?

    < scott:[email protected] > select count(*), to_char(HIREDATE, 'yyyymm')
     2   from emp t
     3  group by to_char(HIREDATE, 'yyyymm')
     4  order by 2;
    
       COUNT(*) TO_CHA
    ------------ ------
              1 198012
              2 198102
              1 198104
              1 198105
              1 198106
              2 198109
              1 198111
              2 198112
              1 198201
              1 198704
              1 198705
    

    regards

    Kay

    btw please choose a more readable name for your avatar. You're more than a number. Have a look at this: Update Your Community Display Name and Avatar!

  • IswaryaR
    IswaryaR Member Posts: 5 Red Ribbon

    SELECT TO_CHAR(HIRE_DATE,'MON') HIRE_MONTH ,COUNT(*) CNT

    FROM EMP

     GROUP BY TO_CHAR(HIRE_DATE,'MON')

     ORDER BY HIRE_MONTH

  • EdStevens
    EdStevens Member Posts: 28,533 Gold Crown

    BTW, this question has nothing to do with the subject of this forum, which is SQL Developer. The question is purely a SQL question, so belongs in the SQL & PL/SQL space.