troubleshooting Question

Problem Query

Avatar of lburnsinmagnolia
lburnsinmagnolia asked on
Microsoft SQL Server
3 Comments1 Solution300 ViewsLast Modified:
Can someone tell me why this query is returning all zeroes for my min, max, and avg functions

SELECT     DATEPART(dw, rsum_date) AS dow, MIN(LateTot / aor) AS MinPct, MAX(LateTot / aor) AS MaxPct, AVG(LateTot / aor) AS AvgPct, UserID
FROM         (SELECT     rsum_date, RAMUSER.UserID, SUM(aor_late_1 + aor_late_2 + aor_late_3 + aor_late_4 + aor_late_5) AS LateTot, MIN(aor) AS aor
                       FROM          rsum, route, ramuser
                       WHERE      aor <> 0 AND rsum_date >= '7/1/2005' AND rsum_date <= '7/31/2005' AND rsum.routeid = route.routeid AND
                                              route.userid = ramuser.userid AND ramuser.userid >= 1 AND ramuser.userid <= 19
                       GROUP BY ramuser.userid, rsum_date) rs1
GROUP BY UserID, DATEPART(dw, rsum_date)

the subquery has dates and values, but the min/max/avg are all returning zeroes.

i.e.
        rsum_date, Userid, LateTot, aor
         7/1/2005,      1,       57,     442
         7/2/2005,      1,       41,     443
...

Thanks for any help

Lburnsinmagnolia
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros