Hello all - lets see if I can stump the audience with this one.
I have a query
The weird thing is I think this is doing the NTILE over the entire collection so when I do the
It is skewed based off the entire data set. If I change the T1 to be like this:
And then just do a Select * FROM T1 the results are accurate.
The issue is that I need to be able to do a group by BG_USER_02 and do calculations off the returned values. There are multiple BG_USER_02's (application names) and i'm trying to do median and a few other things so the results look like this currently:
ignore the closed on values
- Matt
"If I must boast, I will boast of the things that show my weakness"
- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008
I have a query
Code:
WITH TMP_TABLE AS
(
SELECT [BG_USER_02],
DateAdd(Month, DateDiff(Month, 0, CLOSED.MAX_AU_TIME), 0) AS 'ClosedOn',
DATEDIFF(hh, SUB.MIN_AU_TIME, CLOSED.MAX_AU_TIME) AS 'Duration'
FROM RELEASE_CYCLES WITH (NOLOCK),
(
SELECT AU_ENTITY_ID, MIN(AU_TIME) AS MIN_AU_TIME
FROM AUDIT_LOG WITH (NOLOCK), AUDIT_PROPERTIES WITH (NOLOCK)
WHERE AU_ENTITY_TYPE = 'BUG'
AND AP_FIELD_NAME = 'BG_STATUS'
AND AU_ACTION_ID = AP_ACTION_ID
AND AP_NEW_VALUE = 'Submitted'
GROUP BY AU_ENTITY_ID
) AS SUB,
BUG LEFT OUTER JOIN
(
SELECT AU_ENTITY_ID, MAX(AU_TIME) AS MAX_AU_TIME
FROM AUDIT_LOG WITH (NOLOCK), AUDIT_PROPERTIES WITH (NOLOCK)
WHERE AU_ENTITY_TYPE = 'BUG'
AND AP_FIELD_NAME = 'BG_STATUS'
AND AU_ACTION_ID = AP_ACTION_ID
AND AP_NEW_VALUE = 'Closed'
GROUP BY AU_ENTITY_ID
) AS CLOSED
ON CLOSED.AU_ENTITY_ID = BUG.BG_BUG_ID
LEFT OUTER JOIN (SELECT REL_NAME, REL_ID FROM RELEASES) AS RELEASES
ON BUG.BG_DETECTED_IN_REL = RELEASES.REL_ID
WHERE BUG.BG_STATUS = 'Closed'
AND SUB.AU_ENTITY_ID = BUG.BG_BUG_ID
AND CLOSED.AU_ENTITY_ID = BUG.BG_BUG_ID
AND BG_DETECTED_IN_RCYC = RCYC_ID
)
,t1 AS
(
SELECT *,
NTILE(10) OVER (ORDER BY [Duration]) AS [PercentGrp],
NTILE(2) OVER (ORDER BY [Duration]) AS [Ascending],
NTILE(2) OVER (ORDER BY [Duration] DESC) AS [Descending]
FROM TMP_TABLE WITH (NOLOCK)
)
select * from t1
WHERE BG_USER_02 = 'iweb-eu'
The weird thing is I think this is doing the NTILE over the entire collection so when I do the
Code:
select * from t1
WHERE BG_USER_02 = 'iweb-eu'
It is skewed based off the entire data set. If I change the T1 to be like this:
Code:
,t1 AS
(
SELECT *,
NTILE(10) OVER (ORDER BY [Duration]) AS [PercentGrp],
NTILE(2) OVER (ORDER BY [Duration]) AS [Ascending],
NTILE(2) OVER (ORDER BY [Duration] DESC) AS [Descending]
FROM TMP_TABLE WITH (NOLOCK)
GROUP BY [BG_USER_02] = 'iweb-eu'
)
And then just do a Select * FROM T1 the results are accurate.
The issue is that I need to be able to do a group by BG_USER_02 and do calculations off the returned values. There are multiple BG_USER_02's (application names) and i'm trying to do median and a few other things so the results look like this currently:
BG_USER_02 Duration PercGrp Asc Desc
iCare 4300 10 2 1
iCare 4246 10 2 1
eClaims 4186 10 2 1
iCare 4132 10 2 1
CRM-EU 4132 10 2 1
iCare 4062 10 2 1
iCare 4062 10 2 1
IS 3914 10 2 1
CRM-EU 3825 10 2 1
CRM-EU 3824 10 2 1
ignore the closed on values
- Matt
"If I must boast, I will boast of the things that show my weakness"
- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008