Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7046097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:36:36+00:00 2026-05-28T02:36:36+00:00

I have the following query: — Compare current period to historical data select Name

  • 0

I have the following query:

-- Compare current period to historical data
select  Name ,
        avg(TimeProcessing + TimeRendering + TimeDataRetrieval) / 1000  as 'Current Month' ,
        isnull(count(TimeProcessing), 0)                                as 'Sample' ,
        min(l2.[Avg_Exec_Time_Previous_Month])                          as 'Previous Month' ,
        isnull(min(l2.[Executions_Last_Month]), 0)                      as 'Sample' ,
        min(l3.[Avg_Exec_Time_Two_Months_Ago])                          as 'Two Months ago' ,
        isnull(min(l3.[Executions_Two_Months_Ago]), 0)                  as 'Sample'
from    marlin.report_execution_log l
        inner join marlin.report_catalog c on l.ReportID = c.ItemID
        left outer join ( 
                        select    
                            l2.ReportID ,
                            (
                            avg(l2.TimeProcessing + l2.TimeRendering 
                            + l2.TimeDataRetrieval) / 1000 
                            ) as 'Avg_Exec_Time_Previous_Month' ,
                            count(l2.TimeProcessing) as 'Executions_Last_Month'
                        from    
                            marlin.report_execution_log l2
                        where   
                            TimeEnd between dateadd(MONTH, -2, getdate())
                                    and     dateadd(MONTH, -1, getdate())
                        group by  
                            l2.ReportID
                        ) l2 on l.ReportID = l2.ReportID
        left outer join ( 
                        select    
                            l3.ReportID ,
                            (
                            avg(l3.TimeProcessing + l3.TimeRendering + l3.TimeDataRetrieval) / 1000 
                            ) as 'Avg_Exec_Time_Two_Months_Ago' ,
                            count(l3.TimeProcessing) as 'Executions_Two_Months_Ago'
                        from  
                            marlin.report_execution_log l3
                        where 
                            TimeEnd between dateadd(MONTH, -3, getdate())
                                    and     dateadd(MONTH, -2, getdate())
                        group by  
                            l3.ReportID
                        ) l3 on l.ReportID = l3.ReportID
group by    l.ReportID ,
            Name
order by    2 desc

Which brings up the following results:

Results

Unfortunately one our reports changed names throughout the month and subsequently I need to merge these two rows. Is this possible? How can I merge two rows? For example, how could I have the first and second row show additive results using the first rows report name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:36:36+00:00Added an answer on May 28, 2026 at 2:36 am

    If I understood it well you just need a case statement in your select and in your group by.. something like

    select  case when Name = 'Project1' then 'Project1'
                 when Name = 'Project2' then 'Project1'
                 else Name
            end as NAME
    .......
    group by case when Name = 'Project1' then 'Project1'
                 when Name = 'Project2' then 'Project1'
                 else Name
            end
    

    if your case is that now is Project 1 and one month ago was Project 2, you may need to add the date in the case statement (just in case)

     select  case when Name = 'Project1' and TimeEnd = getdate()  then 'Project1'
                     when Name = 'Project2' and TimeEnd = dateadd(MONTH, -1, getdate()) then 'Project1'
                     else Name
                end as NAME
        .......
        group by case when Name = 'Project1' and TimeEnd = getdate()  then 'Project1'
                     when Name = 'Project2' and  TimeEnd = dateadd(MONTH, -1, getdate()) then 'Project1'
                     else Name
            end
    

    That’s the idea.

    Edit.

    I think you have an option if they get repeated but I dont really like it at all

    SELECT NAME, AVG(Current Month) as Current Month, count(Sample) as Sample, min(Previous Month) as Previous Month, min(Sample2) as Sample2, min(Two Months ago) as Two Months ago,
    min(Sample3) as Sample3
    FROM
    (
    select  Name ,
            avg(TimeProcessing + TimeRendering + TimeDataRetrieval) / 1000  as 'Current Month' ,
            isnull(count(TimeProcessing), 0)                                as 'Sample' ,
            min(l2.[Avg_Exec_Time_Previous_Month])                          as 'Previous Month' ,
            isnull(min(l2.[Executions_Last_Month]), 0)                      as 'Sample2' ,
            min(l3.[Avg_Exec_Time_Two_Months_Ago])                          as 'Two Months ago' ,
            isnull(min(l3.[Executions_Two_Months_Ago]), 0)                  as 'Sample3'
    from    marlin.report_execution_log l
            inner join marlin.report_catalog c on l.ReportID = c.ItemID
            left outer join ( 
                            select    
                                l2.ReportID ,
                                (
                                avg(l2.TimeProcessing + l2.TimeRendering 
                                + l2.TimeDataRetrieval) / 1000 
                                ) as 'Avg_Exec_Time_Previous_Month' ,
                                count(l2.TimeProcessing) as 'Executions_Last_Month'
                            from    
                                marlin.report_execution_log l2
                            where   
                                TimeEnd between dateadd(MONTH, -2, getdate())
                                        and     dateadd(MONTH, -1, getdate())
                            group by  
                                l2.ReportID
                            ) l2 on l.ReportID = l2.ReportID
            left outer join ( 
                            select    
                                l3.ReportID ,
                                (
                                avg(l3.TimeProcessing + l3.TimeRendering + l3.TimeDataRetrieval) / 1000 
                                ) as 'Avg_Exec_Time_Two_Months_Ago' ,
                                count(l3.TimeProcessing) as 'Executions_Two_Months_Ago'
                            from  
                                marlin.report_execution_log l3
                            where 
                                TimeEnd between dateadd(MONTH, -3, getdate())
                                        and     dateadd(MONTH, -2, getdate())
                            group by  
                                l3.ReportID
                            ) l3 on l.ReportID = l3.ReportID
    group by    l.ReportID ,
                Name
    )
    group by  Name
    order by    2 desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following SQL query that selects some results from my table: select avg(c3),
I have the following query: Select Name, case when charindex('I',a.S_Data) > 0 then 1
Let's say I have following query: SELECT Id, Name, ForeignKeyId, (SELECT TOP (1) FtName
I have the following query: select mb.id as meter_id ,ds.mydate as mydate ,mb.name as
I have following MySQL query: (SELECT c.Channel as name, count(*) as total_episode FROM (
I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have the following Query and i need the query to fetch data from
I have the following query: SELECT rowid FROM table1 ORDER BY RANDOM() LIMIT 1
I have the following query SELECT e.topicShortName, d.catalogFileID, e.topicID FROM catalog_topics a LEFT JOIN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.