Help needed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help needed

Please someone can tell me how to write a sql code „number of accounts opened per month“ I have accounts opened in different years

22nd Feb 2020, 10:20 AM
Fabrice Kengnang
10 Answers
+ 1
You can use the COUNT function to find the number of accounts and then use GROUP BY to group them on the basis of month.
22nd Feb 2020, 10:45 AM
Avinesh
Avinesh - avatar
0
Not knowing your db/table structure is hard to say. But the GROUP BY clause shoud be the way.
22nd Feb 2020, 10:42 AM
Gabriel Ilie
Gabriel Ilie - avatar
0
the opening dates : dd/mm/yr
22nd Feb 2020, 11:03 AM
Fabrice Kengnang
0
Take a screen shot of the table or share your sql query for further discussion because this will go on non-stop.
22nd Feb 2020, 11:05 AM
Avinesh
Avinesh - avatar
0
KONTO_ID ORT_ID EROEFFNUNGSDATUM 1 18 03.07.2008 2 1 24.11.1999 3 5 05.06.2004 4 12 28.10.1997 5 15 16.01.2016 6 51 29.04.2010 7 60 25.02.2019 8 57 05.05.2010 9 70 22.09.2009 10 54 01.02.2014 11 76 03.10.2016 12 21 12.01.2011 13 76 17.03.2016 14 47 23.08.2007 15 70 08.09.2002 16 12 20.07.1995 17 1 11.06.2009 18 43 10.08.2010 19 21 06.07.2009 20 74 14.02.2005 21 54 10.10.2019 22 1 27.11.2009 23 30 10.05.2016 24 74 02.12.2008 25 68 28.03.2004 26 52 10.03.1996 27 73 28.10.2009 29 7 11.01.2006 30 36 21.08.2003 31 68 03.11.2016 32 5 18.11.2013 33 22 14.11.1997 34 67 12.06.2017 35 75 09.12.2016 36 1 12.08.2010 37 20 17.07.2008 38 19 01.08.1996 39 36 23.04.2004 40 64 27.07.1998 41 72 10.08.2008 42 39 16.08.2019 43 36 16.01.2015 44 32 21.06.2012 45 64 27.04.2012 47 45 09.01.1998 48 21 12.11.2014 49 1 29.04.2001 50 1 22.11.2007 51 67 20.11.1995 52 16 22.10.2004 53 77 27.12.1995 54 4 27.04.2000 55 20 02.02.2011 56 50 11.07.2005 57 1 15.04.2006 58 29 05.06.2010 59 43 16.11.1999 61 70 18.10.2016 62 47 25.01.2010 63 22 23.05.1998 64 64 24.11.2015 65 36 10.07.2011 66 48 15.10.2008 67 16 10.08.1998 68 37 18.03.2018 69 64 12.05.2009 70 8 02.03.1999 71 1 19.10.2013 72 1 23.09.1997 73 72 30.09.1996 75 1 16.08.2012 76 52 18.03.2017 77 63 28.01.2017 78 74 11.10.2003 79 3 10.12.2019 80 43 14.03.2003 81 74 08.02.2003 82 26 18.02.2002 83 26 28.09.2012 84 44 21.06.2002 85 68 16.12.2006 86 54 25.09.2004 88 31 22.10.1997 89 68 04.02.1995 90 1 04.09.2005 91 17 26.02.2003 93 2 04.08.1998 95 1 29.04.2006 96 68 21.10.1999 97 74 17.05.2015 98 55 29.04.2016 99 1 04.03.2010 100 41 24.05.2011 101 35 23.08.2005 102 11 12.12.2007 103 44 05.10.2011 104 37 20.07.2011 105 21 03.10.2018 106 63 22.06.2009 107 64 06.02.2012 108 53 17.02.2008 109 53 18.10.2014 110 36 26.02.2017 112 6 21.04.2004 113 55 29.11.2000 114 60 07.10.2007 115 68 18.04.2003 116 8 16.01.1997 117 31 14.06.2018 118 68 02.12.2014 119 27 24.05.2002 120 65 15.01.2016 121 55 07
22nd Feb 2020, 11:31 AM
Fabrice Kengnang
0
The date column is string? This is SQL Server or MySql?
22nd Feb 2020, 5:00 PM
Gabriel Ilie
Gabriel Ilie - avatar
0
sql
22nd Feb 2020, 5:43 PM
Fabrice Kengnang
0
I am assuming you are using mysql and the date column is string: SELECT COUNT(KONTO_ID) as nr, MONTH(STR_TO_DATE(EROEFFNUNGSDATUM, "%d.%m.%Y")) AS month, YEAR(STR_TO_DATE(EROEFFNUNGSDATUM, "%d.%m.%Y")) AS year GROUP BY YEAR(STR_TO_DATE(EROEFFNUNGSDATUM, "%d.%m.%Y")), MONTH(STR_TO_DATE(EROEFFNUNGSDATUM, "%d.%m.%Y"))
22nd Feb 2020, 6:31 PM
Gabriel Ilie
Gabriel Ilie - avatar
0
Lets' assume you have a tabel call account_tb Select count(account_number) From account_tb Group by month and year;
23rd Feb 2020, 9:48 AM
Nfor Emmanuel Kwala
Nfor Emmanuel Kwala - avatar
0
thks all of you
23rd Feb 2020, 7:33 PM
Fabrice Kengnang