| | |
Select Problem of COUNT on GROUP
![]() |
•
•
Join Date: Jul 2006
Posts: 1
Reputation:
Solved Threads: 0
hi, i am a user of Toad for Oracle 8.6.1
i am having a problem contructing this query
SELECT
FAC.FACILITY_ABBR hall_abbr,
COUNT(HALLUNIT.ACCEPTS_MALES_FLAG) MISDEMEANOR_MALE,
COUNT(HALLUNIT.ACCEPTS_FEMALES_FLAG) MISDEMEANOR_FEMALES
FROM
HALL_UNITS HALLUNIT,
FACILITIES FAC
WHERE
HALLUNIT.HALL_ID = FAC.ID
AND HALLUNIT.ACCEPTS_MALES_FLAG ='T'
AND HALLUNIT.ACCEPTS_FEMALES_FLAG ='T'GROUPBY
FAC.FACILITY_ABBR
the result is:
hall_abbr MISDEMEANOR_MALE MISDEMEANOR_FEMALES
BJNJH 1 1
CJH 2 2
LPJH 2 2
that suppose to be:
hall_abbr MISDEMEANOR_MALE MISDEMEANOR_FEMALES
BJNJH 1 3
CJH 2 3
LPJH 2 3
its copies the result of MISDEMEANOR_MALE to MISDEMEANOR_FEMALES.. and i cant figure out why..
please help me...
thanks
i am having a problem contructing this query
SELECT
FAC.FACILITY_ABBR hall_abbr,
COUNT(HALLUNIT.ACCEPTS_MALES_FLAG) MISDEMEANOR_MALE,
COUNT(HALLUNIT.ACCEPTS_FEMALES_FLAG) MISDEMEANOR_FEMALES
FROM
HALL_UNITS HALLUNIT,
FACILITIES FAC
WHERE
HALLUNIT.HALL_ID = FAC.ID
AND HALLUNIT.ACCEPTS_MALES_FLAG ='T'
AND HALLUNIT.ACCEPTS_FEMALES_FLAG ='T'GROUPBY
FAC.FACILITY_ABBR
the result is:
hall_abbr MISDEMEANOR_MALE MISDEMEANOR_FEMALES
BJNJH 1 1
CJH 2 2
LPJH 2 2
that suppose to be:
hall_abbr MISDEMEANOR_MALE MISDEMEANOR_FEMALES
BJNJH 1 3
CJH 2 3
LPJH 2 3
its copies the result of MISDEMEANOR_MALE to MISDEMEANOR_FEMALES.. and i cant figure out why..
please help me...
thanks
This is a logic error you are asking where MALE AND FEMALE = 'T'
By definition that filters out any records where MALE <> 'T' OR FEMALE <> 'T'
try this, let me know if it works
By definition that filters out any records where MALE <> 'T' OR FEMALE <> 'T'
try this, let me know if it works
SELECT FAC.FACILITY_ABBR hall_abbr, COUNT(HALLUNIT.ACCEPTS_MALES_FLAG) MISDEMEANOR_MALE, COUNT(HALLUNIT.ACCEPTS_FEMALES_FLAG) MISDEMEANOR_FEMALES FROM HALL_UNITS HALLUNIT, FACILITIES FAC WHERE HALLUNIT.HALL_ID = FAC.ID AND HALLUNIT.ACCEPTS_MALES_FLAG ='T' OR HALLUNIT.HALL_ID = FAC.ID AND HALLUNIT.ACCEPTS_FEMALES_FLAG ='T'
Last edited by hollystyles; Jul 12th, 2006 at 10:55 am.
![]() |
Similar Threads
- SQL Query Problem (Oracle)
- problem for a simple asp.net query (ASP)
- RunTime 3075, cant see the problem? And Values are as they should be... (Visual Basic 4 / 5 / 6)
- MySQL RecordCount Problems (MySQL)
- is order by and group by the same? (MySQL)
- Need Help on SQL Query for select statement (MS SQL)
- member group query (MySQL)
Other Threads in the IT Professionals' Lounge Forum
- Previous Thread: Cool Games and Source Code
- Next Thread: can anyone help me out...
| Thread Tools | Search this Thread |
1gbit advertising advice amazon archive british broadband business businessprocesses career censorship cern china cio collectiveintelligence connectivity consumer consumers corporateearnings datatransfer debtcollectors dictionary digg digital ebay ecommerce email employment environment facebook food government grid high-definition hottub infodelivery infotech intel internet interview ipod isp japan kindle lhc library malware marketing mit moonfruit news onlineshopping piracy piratebay pope porn program r&d religion remoteworking research retail security sex shopping simple skype smallbusiness smb socialmedia socialnetworking software softwareengineer spam speed spending startrek statistics stocks study stumbleupon survey tabletpc technology touch-screen touchscreen twitter uk videoinprint voips web webdeveloper windows words






