dbTalk Databases Forums  

Messed Up Query

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Messed Up Query in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mtek
 
Posts: n/a

Default Messed Up Query - 04-28-2008 , 12:51 PM







Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......

Thanks!

John



Reply With Quote
  #2  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: Messed Up Query - 04-28-2008 , 06:17 PM






Mtek wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I can't tell for sure, but it sounds like you just need an analytical
function in the outer query...

count(*) over (partition by vh.ticker)

....or a selective count...

sum(decode(vh.q1_shares, 0, 1, 0)) over (partition by vh.ticker)

--
Peter


Reply With Quote
  #3  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: Messed Up Query - 04-28-2008 , 06:17 PM



Mtek wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I can't tell for sure, but it sounds like you just need an analytical
function in the outer query...

count(*) over (partition by vh.ticker)

....or a selective count...

sum(decode(vh.q1_shares, 0, 1, 0)) over (partition by vh.ticker)

--
Peter


Reply With Quote
  #4  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: Messed Up Query - 04-28-2008 , 06:17 PM



Mtek wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I can't tell for sure, but it sounds like you just need an analytical
function in the outer query...

count(*) over (partition by vh.ticker)

....or a selective count...

sum(decode(vh.q1_shares, 0, 1, 0)) over (partition by vh.ticker)

--
Peter


Reply With Quote
  #5  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: Messed Up Query - 04-28-2008 , 06:17 PM



Mtek wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I can't tell for sure, but it sounds like you just need an analytical
function in the outer query...

count(*) over (partition by vh.ticker)

....or a selective count...

sum(decode(vh.q1_shares, 0, 1, 0)) over (partition by vh.ticker)

--
Peter


Reply With Quote
  #6  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Messed Up Query - 04-29-2008 , 04:18 AM



On Apr 28, 7:51 pm, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I don't see a join with q10. Is a cross join really what you intend?

robert


Reply With Quote
  #7  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Messed Up Query - 04-29-2008 , 04:18 AM



On Apr 28, 7:51 pm, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I don't see a join with q10. Is a cross join really what you intend?

robert


Reply With Quote
  #8  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Messed Up Query - 04-29-2008 , 04:18 AM



On Apr 28, 7:51 pm, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I don't see a join with q10. Is a cross join really what you intend?

robert


Reply With Quote
  #9  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Messed Up Query - 04-29-2008 , 04:18 AM



On Apr 28, 7:51 pm, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......
I don't see a join with q10. Is a cross join really what you intend?

robert


Reply With Quote
  #10  
Old   
Mtek
 
Posts: n/a

Default Re: Messed Up Query - 04-29-2008 , 07:20 AM



On Apr 29, 4:18 am, Robert Klemme <shortcut... (AT) googlemail (DOT) com> wrote:
Quote:
On Apr 28, 7:51 pm, Mtek <m... (AT) mtekusa (DOT) com> wrote:



Hi,

I have this query:

SELECT q10.q10_count,
vi.mgr_flag,vi.inst_type,vi.inst_num,vi.inst_cst,v i.inst_zip,vi.inst_phone,vi.url,vi.turnover,vi.hol d_cnt,
vi.date_,vi.inst_size,vi.inst_dchg,

vh.ticker,vh.q0_shares,vh.q1_shares,vh.q0q1_grwth, vh.q0q1_dchg,vh.shares_out,
mt.comp_name, sd.sector_name, p.closing
FROM vinst vi, vhold vh, master_table mt, stock_data sd, prices p,
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10
WHERE inst_name = 'Yacktman Fund'
AND 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;

Take a look at the inner query in the FROM clause:
(SELECT count(*) q10_count FROM vhold vh
WHERE q1_shares = 0 GROUP BY vh.ticker) q10

I basically need the same criteria applied as the outer query. Do I
have to re-list the criteria? I'll have to do that count for 5
fields. It will make this query WAY long.......

I don't see a join with q10. Is a cross join really what you intend?

robert

Well, I want to select a certain criteria from X number of tables. I
also want a COUNT of certain columns with their own critera. And, I'm
trying to put this all into one query.......



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.