Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Oracle Miscellaneous > Re: Limit query...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 6890 of 7280
Post > Topic >>

Re: Limit query output to a single record based on combination of

by Urs Metzger <urs@[EMAIL PROTECTED] > May 12, 2008 at 05:36 PM

Sa**** schrieb:
> On May 12, 10:55 am, Urs Metzger <u...@[EMAIL PROTECTED]
> wrote:
>> Sa**** schrieb:
>>
>>> Hi all,
>>> I have a query as follows:
>>> Select building, floor from T1
>>> I would like to limit the output where the building, floor combination
>>> is present only once in the output.
>>> For example, if the output is
>>> blgdA, 2
>>> bldgA, 3
>>> bldgA, 3
>>> bldgB, 1
>>> bldgB, 2
>>> bldgB, 2
>>> I would like to filter it so that the output is only
>>> blgdA, 2
>>> bldgB, 1
>>> I'm not sure about how to do this.
>>> Can someone help out?
>>> Thanks,
>>> Sa****
>> Search the docs for GROUP BY and HAVING.
>>
>> htht,
>> Urs Metzger
> 
> Thank you.
> So I modified the query thus:
> select bldg, count(Floor)
> from T
> group by bldg
> having count(Floor) =1
> 
> However, when I try to include the floor number
> select  lbcode_key,  count(floor ), floor
> it fails:  ORA-00979: not a GROUP BY expression 
> I want to be able to see the floor number.
> Also there is another field "type" and I need to filter it by this
> field as well, to include the regexp '%Switch'.
> 
> So my original query should have been:
> Select building, floor from T1 where type like '%Switch'
> 
> However, the where clause is disallowed when using group by and the
> having clause doesn't like this either.
> 
> How do I do this?
OK:

select bldg, floor
from T
group by bldg, floor
having count(*) = 1

hth,
Urs Metzger
 




 5 Posts in Topic:
Limit query output to a single record based on combination of fi
Sashi <smalladi@[EMAIL  2008-05-12 07:43:11 
Re: Limit query output to a single record based on combination o
Urs Metzger <urs@[EMAI  2008-05-12 16:55:12 
Re: Limit query output to a single record based on combination o
Sashi <smalladi@[EMAIL  2008-05-12 08:13:34 
Re: Limit query output to a single record based on combination o
Urs Metzger <urs@[EMAI  2008-05-12 17:36:01 
Re: Limit query output to a single record based on combination o
Urs Metzger <urs@[EMAI  2008-05-12 17:40:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 0:17:25 CST 2008.