Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issues combining a Subquery

Rundas2000Mar 19 2017 — edited Mar 20 2017

Hello community,

Im having a lot of trouble combining these two queries. Im close to graduating my college with a bachelors degree in database administration. However my strong point relies on MS SQL, now going back into SQL developer i have been struggling a bit. A classmate has provided me questions she receives in class and i appreciate it as a way to practice and improve my skills.

The question is this: (Note this is base of the "cityjails" table provided with the Oracle 11g SQL book by Joan Casteel)

List the names of probation officers who have had less than the average number of criminals assigned.

I created this so far, but im getting multiple names even though i added the distinct clause.

//

SELECT Distinct (FIRST ||' '|| LAST) AS "Probation Officers", A.CRIMINAL_ID, A.PROB_ID

FROM SENTENCES A

JOIN PROB_OFFICERS B ON

A.PROB_ID = B.PROB_ID

WHERE A.PROB_ID < (SELECT AVG(CRIMINAL_ID) FROM SENTENCES)

//

These are the results.

pastedImage_0.png

Any idea what im doing wrong?

Thank you.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2017
Added on Mar 19 2017
15 comments
585 views