0

I am trying to group by job id while having it count the milliseconds in each row of the job id.

For example ill have 5 rows of job 55 all with different milliseconds like .3, .5, 1.5, .3, .4. I don't want it to display 5 rows, only one like this: 55 | 3.0

This is how far i've gotten i just need a little nudge int eh right direction.

SELECT job_ID, AVG_REC_TIME_MILLIS, count(AVG_REC_TIME_MILLIS)
FROM job_step js
GROUP BY js.JOB_ID;
2
  • 3
    Hint : SUM instead of COUNT(). Commented Nov 21, 2018 at 15:34
  • Could you please more elaborate with table format data Commented Nov 21, 2018 at 15:36

2 Answers 2

1

You need SUM() instead of COUNT() & SELECT statement should contains only columns which are aggregated when GROUP BY involved so, AVG_REC_TIME_MILLIS doesn't make any sense.

So, removed it from SELECT statement :

SELECT job_ID, SUM(AVG_REC_TIME_MILLIS)
FROM job_step js
GROUP BY js.JOB_ID;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! this is exactly what im looking for!
0

If you need to get the sum of all milliseconds for a job_id then

SELECT job_ID, sum(AVG_REC_TIME_MILLIS)
FROM job_step js
GROUP BY js.JOB_ID;

If number of job steps is what you need then consider the following query

SELECT job_ID, count(AVG_REC_TIME_MILLIS)
    FROM job_step js
    GROUP BY js.JOB_ID;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.