I
imad hammad
My database stores Facilities, the units that belong to each facility and
then the Devices that belong to each unit in that facility. Each device was
used to test patients as well.
What I have been trying to accomplish for about a week now, is a count!
The result I am looking for is basically the number of units,devices and
patients tested PER facility.
So something like this:
# Units # devices # patients tested
Facility 1 - - -
Facility 2 - - -
Facility 3 - - -
Now what is making this really difficult for me is that I do NOT want to
count duplicates. In my database only the patients would be duplicates as the
same patient is usually tested many times on a single device.
I have been using the Group By predicate to get a count per facility, and it
works fine to find the # of units or # of devices seperately but when i try
to accomplish this in one query i get the wrong count...for instance:
SELECT LOCATION.FACILITY, Count(LOCATION.UNIT) AS CountOfUNIT,
Count(COMPUTER.COMP_ID) AS CountOfCOMP_ID
FROM LOCATION INNER JOIN COMPUTER ON LOCATION.LOC_ID = COMPUTER.LOC_ID
GROUP BY LOCATION.FACILITY;
is returning the wrong answer.
I was hoping i could solve this problem first, and then worry about counting
the patients per device as I can tell that will be even more difficult.
Some more information about my tables
Location Table Device Table
Loc_ID -----| Comp_ID
Facility |-------Loc_ID
Building Type
Unit Ram
Floor IP_Address
Zone
then the Devices that belong to each unit in that facility. Each device was
used to test patients as well.
What I have been trying to accomplish for about a week now, is a count!
The result I am looking for is basically the number of units,devices and
patients tested PER facility.
So something like this:
# Units # devices # patients tested
Facility 1 - - -
Facility 2 - - -
Facility 3 - - -
Now what is making this really difficult for me is that I do NOT want to
count duplicates. In my database only the patients would be duplicates as the
same patient is usually tested many times on a single device.
I have been using the Group By predicate to get a count per facility, and it
works fine to find the # of units or # of devices seperately but when i try
to accomplish this in one query i get the wrong count...for instance:
SELECT LOCATION.FACILITY, Count(LOCATION.UNIT) AS CountOfUNIT,
Count(COMPUTER.COMP_ID) AS CountOfCOMP_ID
FROM LOCATION INNER JOIN COMPUTER ON LOCATION.LOC_ID = COMPUTER.LOC_ID
GROUP BY LOCATION.FACILITY;
is returning the wrong answer.
I was hoping i could solve this problem first, and then worry about counting
the patients per device as I can tell that will be even more difficult.
Some more information about my tables
Location Table Device Table
Loc_ID -----| Comp_ID
Facility |-------Loc_ID
Building Type
Unit Ram
Floor IP_Address
Zone