DEV Community

joe
joe

Posted on

Need help with GROUP BY

I need some SLQ help that I will then use within Tableau to create some custom stuff. Thanks in advance!

I am building a visual for time in status for issues. I have some issues that went into a 'working' state multiple times. I need to aggregate that into one collective qty of time in that state.

SELECT 

    [Issue ID]
    ,[Status Name]
    ,[Status Category]
    ,IIF([Status Exit Datetime] is null, GETDATE(), [Status Enter Datetime]) as 'EXIT Date'
    ,SUM([No Of Seconds in Current Status]) AS 'seconds in state'



    INTO #tempTable


    FROM MY-SQL-TABLE
    WHERE [Issue ID] = '7928712'
    GROUP BY [Status Name],[Status Category], [Issue ID],[Status Enter Datetime] ,[Status Exit Datetime]





    SELECT * FROM #tempTable
Enter fullscreen mode Exit fullscreen mode

This is what I am getting.

Image description

I need to return the 'working' rows as one row?

Top comments (0)