SQL query problem - (internal has not managed to the outer query)

Hi all:

Here is my SQL query:
SELECT RD.SITE,
  ROUND(
  (SELECT COUNT (DISTINCT PB.EMP_ID)
  FROM BOOK PB
  WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    )
  ) /
  (SELECT COUNT (DISTINCT PB.EMP_ID)
  FROM BOOK PB
  WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
WHERE MO.QUALIFIER > 4
    )
  )* 100, 2) AS PERCENTAGE
FROM BOOK PB
LEFT JOIN POSITION MO
ON PB.EMP_ID = PO.EMP_ID
INNER JOIN PHYS_LOCATION RD
ON MO.HOUSED         = RD.SITE_ID
WHERE MO.ACTUAL_END IS NULL
GROUP BY RD.SITE;
Why am I the overall percentage of all Sites as opposed to each percentage calculation for each site. I've grouped by Rd. SITE, so I assume he would calculate the percentages for each site. What I've done wrong?

Thank you for your help.

AquaNX4 wrote:
Hi all:

Here is my SQL query:

SELECT RD.SITE,
ROUND(
(SELECT COUNT (DISTINCT PB.EMP_ID)
FROM BOOK PB
WHERE PB.EMP_ID IN
(SELECT PB.EMP_ID FROM BOOK PB
)
) /
(SELECT COUNT (DISTINCT PB.EMP_ID)
FROM BOOK PB
WHERE PB.EMP_ID IN
(SELECT PB.EMP_ID FROM BOOK PB
WHERE MO.QUALIFIER > 4
)
)* 100, 2) AS PERCENTAGE
FROM BOOK PB
LEFT JOIN POSITION MO
ON PB.EMP_ID = PO.EMP_ID
INNER JOIN PHYS_LOCATION RD
ON MO.HOUSED         = RD.SITE_ID
WHERE MO.ACTUAL_END IS NULL
GROUP BY RD.SITE;

Why am I the overall percentage of all Sites as opposed to each percentage calculation for each site. I've grouped by Rd. SITE, so I assume he would calculate the percentages for each site. What I've done wrong?

It's what you're asking. Your subquery scalar to get the percentage is not restricted by the current site. Add columns to filter to restrict the values selected for the calculation

Published by: riedelme on May 8, 2013 07:26

Tags: Database

Similar Questions

Maybe you are looking for

  • Satellite L650-OED under construction speakers of crackling and his intermittent

    Hello. I just buy a new laptop (L650-OED) that is running windows 7-32 bit. The built-in speakers make a crackling noise and do work only intermittently. When you adjust the volume upward or down, they work for a few seconds and then cut. I tested th

  • Download unexpected iMovie

    iMovie tries to hug to download (2G) and I have no idea why, or what it is.  Any suggestions? I can pause via Launchpad, but no other real options are offered.  Either let it download or Dungeon, he paused. Thank you Mike

  • Droid Life indicates an update to D3

    I've seen three (. 903,.905 et.906) potential updates floating around the net in the last month or so. I suppose that the latter is the version that we will actually get. http://www.droid-life.com/2012/03/07/droid-3-looking-at-new-update-from-Motorol

  • I've been locked out of the Xbox.

    Original title: x - box locked out Please can someone help, Im locked out of my x - box, don't remember not security issue, cannot answer e-mail question as don't send emails, pay for a gold at the store subscription and have more card with number an

  • What will happen to the existing recovery partition

    I have an Inspiron desktop with a pre-installed recovery disc/partition. I am currently running Windows 7. What will happen to that partition and its content, should I decide to use the free update of Microsoft for host1 0? Should what steps I take,