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 Server > Re: Shorten Que...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 16485 of 17269
Post > Topic >>

Re: Shorten Query

by Urs Metzger <urs@[EMAIL PROTECTED] > Apr 29, 2008 at 09:07 PM

Mtek schrieb:
> On Apr 29, 12:51 pm, Urs Metzger <u...@[EMAIL PROTECTED]
> wrote:
>> Mtek schrieb:
>>
>>> Hi,
>>> Please look at this query.  notice that most of the criteria is the
>>> same, except for 1 line.  I need to get the count for 10 items.  Is
>>> there a better way to do this so I do not have to repeat the criteria
>>> for each item I want to return?
>>> I realize that one line of the criteria is different, but I am hoping
>>> to not have to repeat the other criteria.....
>>> SELECT a.q1, b.q2
>>> FROM (SELECT count(*) q1
>>>       FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices
>>> p
>>>       WHERE vi.inst_num = vh.inst_num
>>>         AND vh.ticker = mt.ticker
>>>         AND mt.m_ticker = sd.m_ticker
>>>         AND mt.m_ticker = p.m_ticker
>>>         AND q1_shares = 0) a,
>>>      (SELECT count(*) q2
>>>       FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices
>>> p
>>>       WHERE vi.inst_num = vh.inst_num
>>>         AND vh.ticker = mt.ticker
>>>         AND mt.m_ticker = sd.m_ticker
>>>         AND mt.m_ticker = p.m_ticker
>>>         AND q0_shares = 0) b;
>>> Thank you much,
>>> John
>> SELECT SUM(DECODE(q1_shares, 0, 1, 0)) as q1,
>>         SUM(DECODE(q0_shares, 0, 1, 0)) as q2
>>    FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p
>>    WHERE vi.inst_num = vh.inst_num
>>      AND vh.ticker = mt.ticker
>>      AND mt.m_ticker = sd.m_ticker
>>      AND mt.m_ticker = p.m_ticker;
>>
>> hth,
>> Urs Metzger
> 
> 
> Your solution is interesting.  In fact, I like it.  Is this possible
> also if I need to use a > or <?
> 
> The actual results they are looking for is:
> 
> -- A count of the number of tickers that have Q1_SHARES = 0
> -- A count of the number of tickers that have Q0_SHARES = 0
> -- A count of the number of tickers that have Q1_SHARES > Q0_SHARES
> -- A count of the number of tickers that have Q1_SHARES < Q0_SHARES
> -- A count of the number of tickers that have Q1_SHARES = Q0_SHARES
> 
You can use CASE rather than DECODE.

Urs
 




 6 Posts in Topic:
Shorten Query
Mtek <mtek@[EMAIL PROT  2008-04-29 09:02:27 
Re: Shorten Query
Urs Metzger <urs@[EMAI  2008-04-29 19:49:50 
Re: Shorten Query
Urs Metzger <urs@[EMAI  2008-04-29 19:51:46 
Re: Shorten Query
Mtek <mtek@[EMAIL PROT  2008-04-29 11:32:23 
Re: Shorten Query
Urs Metzger <urs@[EMAI  2008-04-29 21:07:37 
Re: Shorten Query
Mtek <mtek@[EMAIL PROT  2008-04-29 12:10:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Oct 11 20:13:28 CDT 2008.