Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find number of occurences of event per day – SQL

I’m trying to set up some monitoring in my SQL database.

select
        gn.Goal_Name_
        ,gn.EventTimestamp as   Timestamp
        --,Max(EventTimestamp) as   Timestamp
        from(
            select CASE when substr(GoalName,1,3)='MSD' then 'MSD' when substr(GoalName,1,5)='https' then 'https' else goalname END as Goal_Name_ 
                    
                    ,EventTimestamp
                from    CG.Goal as goal
        )gn
        group by 1,2      

Produces a table with a structure like:

Goal_Name_ Timestamp
MSD 05.03.2021 11:05:20.162
Logout 18.01.2022 20:07:29.799
Login 23.01.2022 09:12:16.597
etc etc

The problem i’m having is finding a way to count each distinct Goal Name for each day. Find the daily occurence really.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are almost there. The only thing missing is converting your timestamp to date and count the number of rows.

select
     gn.Goal_Name_
     ,CAST(gn.EventTimestamp AS DATE FORMAT 'YYYY/MM/DD') as eventDay
     ,Count(*) as   GoalsCount
     from(
          select CASE when substr(GoalName,1,3)='MSD' then 'MSD' when 
          substr(GoalName,1,5)='https' then 'https' else goalname END as Goal_Name_ 
          ,EventTimestamp
          from CG.Goal as goal
     )gn
group by 1,2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading