Help in Sql Query

Manish Goyal

Manish Goyal

@manish-r2Hoep Oct 21, 2024
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

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Sep 9, 2013

    select count(YourDateCol), to_char(YourDateCol,'YYYY') from YourTable group by YourDateCol order by YourDateCol asc;
  • Shailaja Tiwari

    Shailaja Tiwari

    @shailaja-tiwari-lKhGjd Sep 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.