Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8929941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:46:43+00:00 2026-06-15T08:46:43+00:00

I’m doing a class assignment and seem to be having some trouble with one

  • 0

I’m doing a class assignment and seem to be having some trouble with one question. The question requires me two join 3 tables and count the overall number of occurrences for each row.

This is the join command I have so far (need to figure out where I can put a nested count(distinct):

SELECT litwork.btitle,
       bookcopy.copy_num,
       request.rdate
FROM   litwork,
       bookcopy,
       request
WHERE  litwork.lit_id = bookcopy.lit_id
       AND bookcopy.persidh = request.persid
ORDER  BY btitle;  

The join gives me this table as result:

BTITLE           COPY_NUM        RDATE
--------------- --------------  -------
Bankers          2                18-oct-2012
Bankers          2                30-oct-2012
Blue Ridge       1                20-oct-2012
Linux            1                18-oct-2012
Linux            1                30-oct-2012
My Life          3                31-oct-2012
O-O Design       1                30-oct-2012
O-O Design       3                25-oct-2012
O-O Design       3                18-oct-2012

So how would I make a count(distinct) for all three column within that one command? I’m using standard SQL

Edit to add question prompt (copied and paste):

Show how many requests and how many copies exist for each book that is requested. Show title, number of requests, number of copies of the book. Show in order by title. The SQL query for this question mixes a join with count. To understand such a query, be aware that the join must be processed before the count function .

Be also aware that the join may create duplicate data, so that you should use the count(distinct ..) form of count where needed. (Suggestions: if you have trouble with this question, look at the results of the join without count and group, and figure out how you would perform the required count if these results were data of an existing table. Please do not show this extra query in your report.).

Assumption: a given customer may not have more than one request of the same book.. Note that when joining the table REQUEST with the table BOOK_COPY, the number of rows where a given book appears is the product of the number of requests for that book and of the number of copies.

UPDATE: It’s still not 100% correct..

Additional Tables used for the Join (First one is LITWORK table, second one is REQUEST table, and last one is BOOKCOPY table)

    LIT_ID BTITLE                YEAR
---------- --------------- ----------
      1001 The Trojans           2000
      1002 My Life               2001
      1003 Nature                1998
      1004 Blue Ridge            1996
      1005 True Java             2012
      1006 CPlus                 2004
      1007 Streaming             2000
      1008 MyApps                1998
      1009 O-O Design            2012
      1010 Camping               1978
      1011 Bankers               1970
      1012 Linux                 1962


    LIT_ID     PERSID BNAME    RDATE            RTIME
---------- ---------- -------- ----------- ----------
      1001         11 College  18-oct-2012
      1001          7 College  25-oct-2012
      1003          8 La Jolla 20-oct-2012
      1005          7 Pacific  18-oct-2012
      1008         11 Atlantic 30-oct-2012
      1008          1 College  30-oct-2012
      1012          4 La Jolla 31-oct-2012

    LIT_ID   COPY_NUM PERSID_OUT DATE_OUT    DATE_DUE       PERSIDH HDATE       BNAMEP   BNAMEC
---------- ---------- ---------- ----------- ----------- ---------- ----------- -------- --------
      1001          1          4 13-sep-2012 27-nov-2012                        La Jolla
      1002          1                                                           Pacific  Atlantic
      1002          2          1 02-sep-2012 12-oct-2012                        Pacific
      1002          3                                             4 15-nov-2012 La Jolla La Jolla
      1003          1          9 10-dec-2012 30-dec-2012                        Pacific
      1003          2          1 13-dec-2012 22-jan-2013                        La Jolla
      1003          3                                                           Atlantic Atlantic
      1004          1                                             8 19-nov-2012 Pacific  College
      1004          2          4 04-dec-2012 17-feb-2013                        Pacific
      1004          3         10 11-oct-2012 31-oct-2012                        Atlantic
      1005          1          4 27-oct-2012 10-jan-2013                        La Jolla
      1005          2          1 19-sep-2012 29-oct-2012                        Pacific
      1006          1          7 29-jan-2012 09-mar-2012                        Pacific
      1006          2          1 07-jan-2012 16-feb-2012                        College
      1006          3                                                           Pacific  College
      1007          1          1 26-oct-2012 05-dec-2012                        Pacific
      1007          2                                                           Pacific  College
      1007          3          6 15-oct-2012 04-nov-2012                        La Jolla
      1008          1          4 23-oct-2012 06-jan-2013                        College
      1008          2          3 15-oct-2012 24-nov-2012                        Pacific
      1009          1                                             1 20-nov-2012 Pacific  Pacific
      1009          2         11 28-sep-2012 12-dec-2012                        Pacific
      1009          3                                             7 22-nov-2012 La Jolla College
      1010          1          1 01-sep-2012 11-oct-2012                        Pacific
      1011          1          4 31-jan-2012 15-apr-2012                        La Jolla
      1011          2                                            11 20-nov-2012 College  La Jolla
      1012          1                                            11 19-nov-2012 Pacific  Atlantic
      1012          2          3 29-oct-2012 08-dec-2012                        Pacific

This is my current SQL command (not the one I got from Gordon Linoff’s comment–that one gave me 2-3 extra rows)

select   litwork.btitle, 
         count(distinct bookcopy.copy_num), 
         count(distinct request.rdate)
from     litwork, 
         bookcopy, 
         request 
where    litwork.lit_id=request.lit_id and
         bookcopy.persidh=request.persid 
group by btitle;

And that gives me this table (which you can see I have all the correct amount of rows [when you take out the duplicates] but the count numbers are wrong)

BTITLE          COUNT(DISTINCTBOOKCOPY.COPY_NUM) COUNT(DISTINCTREQUEST.RDATE)
--------------- -------------------------------- ----------------------------
Linux                                          1                            1
MyApps                                         2                            1
Nature                                         1                            1
The Trojans                                    3                            2
True Java                                      1                            1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:46:45+00:00Added an answer on June 15, 2026 at 8:46 am

    The following should work with Oracle’s SQL *Plus:

    select litwork.btitle, count(distinct bookcopy.copy_num), count(distinct request.rdate)
    from litwork, bookcopy, request
    where litwork.lit_id = request.lit_id and request.lit_id = bookcopy.lit_id(+)
    group by litwork.btitle;
    

    For more info on joins see Oracle SQL*Plus Pocket Reference, 2nd Edition.

    Possible solutions to count issue:

    • Change count(distinct request.rdate) to count(distinct request.PERSID).
    • Change count(distinct request.rdate) to count(distinct request.*).
    • Change count(distinct request.rdate) to sum(case when request.rdate is null then 0 else 1 end)
    • Instead of joining the request table you could join (select lit_id, count(*) as requestCount from request group by lit_id) then select requestCount.

    This is probably the best I can do since I do not have the detailed definition of the fields and how they relate. It would also help if I had the expected results and SQL *Plus to test it with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.