Unsupported Screen Size: The viewport size is too small for the theme to render properly.

Database Administration

forums forums SQLyog Query Builder and Schema Designer Database Administration

  • This topic is empty.
Viewing 3 reply threads
  • Author
    Posts
    • #12164
      Diana Magers
      Member

      I need to write and execute a command to retrieve the branch number and units for each branch having more than 25 books on hand.

      Tables

      BRANCH: BRANCH_NUM, BRANCH_NAME, BRANCH_LOCATION, NUM_EMPLOYEES

      INVENTORY: BOOK_CODE, BRANCH_NUM, ON_HAND

      THIS IS WHAT i HAVE SO FAR:

      SELECT BRANCH.BRANCH_NUM, INVENTORY.ON_HAND

      FROM INVENTORY, BRANCH

      WHERE BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM

      AND INVENTORY.ON_HAND > '25';

      ALL I AM COMING UP WITH IS THE TWO COLUMN HEADINGS: BRANCH_NAME AND NUM_EMPLOYEES.

      I DEFINITELY NEED HELP WITH THIS ONE. PLEASE.

    • #31583
      peterlaursen
      Participant

      Well .. then te query returns an empty set  (no rows satisfies the condition).

      Take an analytical approach .. simplify.  Do these queries return what you'd expect?

      1)

      SELECT COUNT(ON_HAND)

      FROM INVENTORY

      WHERE INVENTORY.ON_HAND > '25';

      2)

      SELECT BRANCH.BRANCH_NUM, INVENTORY.ON_HAND

      FROM INVENTORY, BRANCH

      WHERE BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM';

      If somebody should be able to help you you will need to post an exact case with table definitions and sample data.

    • #31584
      Diana Magers
      Member
      'peterlaursen' wrote:

      Well .. then te query returns an empty set  (no rows satisfies the condition).

      Take an analytical approach .. simplify.  Do these queries return what you'd expect?

      1)

      SELECT COUNT(ON_HAND)

      FROM INVENTORY

      WHERE INVENTORY.ON_HAND > '25';

      2)

      SELECT BRANCH.BRANCH_NUM, INVENTORY.ON_HAND

      FROM INVENTORY, BRANCH

      WHERE BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM';

      If somebody should be able to help you you will need to post an exact case with table definitions and sample data.

      Actually it came out to be:

      SELECT BRANCH.BRANCH_NUM, SUM(INVENTORY.ON_HAND) as UnitsOnHand

      FROM BRANCH JOIN INVENTORY

      ON BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM

      GROUP BY BRANCH.BRANCH_NUM

      HAVING SUM(INVENTORY.ON_HAND)>25

    • #31585
      Diana Magers
      Member
      'peterlaursen' wrote:

      Well .. then te query returns an empty set  (no rows satisfies the condition).

      Take an analytical approach .. simplify.  Do these queries return what you'd expect?

      1)

      SELECT COUNT(ON_HAND)

      FROM INVENTORY

      WHERE INVENTORY.ON_HAND > '25';

      2)

      SELECT BRANCH.BRANCH_NUM, INVENTORY.ON_HAND

      FROM INVENTORY, BRANCH

      WHERE BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM';

      If somebody should be able to help you you will need to post an exact case with table definitions and sample data.

      Actually it came out to be:

      SELECT BRANCH.BRANCH_NUM, SUM(INVENTORY.ON_HAND) as UnitsOnHand

      FROM BRANCH JOIN INVENTORY

      ON BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM

      GROUP BY BRANCH.BRANCH_NUM

      HAVING SUM(INVENTORY.ON_HAND)>25

Viewing 3 reply threads
  • You must be logged in to reply to this topic.