Skip to content
Advertisement

Group by month and name SQL

I need some help with SQL.

I have

  • Table1 with columns Id, Date1 and Date2

  • Table2 with columns Table1Id and Table2Id

  • Table3 with columns Id and Name

Here is my try:

I need to take Count(date2)/Count(date1) grouped by monthes and name. I have no idea how to do that, as there is no table with monthes. DB – Postgres

sample data from comment:

Desired result:

Update: if count(date2) == 0, than count(date2) = -1

Advertisement

Answer

Source answer

Here code for my question thats work. And yeah, i’ve asked it on ru too.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement