CrazyEngineers
  • Manish
    Manish

    MemberSep 9, 2013

    Help in Sql Query

    I have a database table with following cols

    Id, Name, Date (FORMAT: Y-m-d H:i:s)

    Now I want to retrieve data of following form

    Count Year
    3 2013
    5 2014

    It is showing total no of records generated in different years

    For eg If I have following data

    1 Manish 2013-10-01 23:12:12
    2 Tarun 2013-10-02 23:12:12
    3 Pankaj 2014-10-02 23:12:12
    4 Pankaj 2015-10-02 23:12:12,

    Then it will return me following data

    Count Year
    2 2013
    1 2014
    1 2015

    Is it possible?
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberSep 9, 2013

    select count(YourDateCol), to_char(YourDateCol,'YYYY') from YourTable group by YourDateCol order by YourDateCol asc;
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberSep 9, 2013

    I'm not sure about this as I'm still learning but just check using
    Count() and group by clause applied on year.

    I don't have a datbase in my PC otherwise I could have myself checked it out.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register