Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: 2 queries with one select :is it possible???

Re: 2 queries with one select :is it possible???

From: cf <news_at_sitinfo.com>
Date: Thu, 13 Sep 2001 10:28:07 +0200
Message-ID: <3ba06e17$0$14591$4d4eb98e@read.news.fr.uu.net>


select Q1.evt_code,Q1.EVT,Q1.C1,Q2.C2
from
(select evt_code,to_char(EVT_COMPLETED,'mm') EVT,count(*) C1 from T1
where EVT_COMPLETED between :begindate_param and :enddate_param and status='C'
group by EVT_code, to_char(EVT_COMPLETED,'mm')) Q1, (select evt_code,to_char(EVT_target,'mm') EVT,count(*) C2 from T1
where EVT_target < :begindate_param
and status='A'
group by EVT_code, to_char(EVT_target,'mm')) Q2 where Q1.evt_code = Q2.evt_code
and Q1.evt = Q2.evt

Cordialement Christophe.

"gil guerillot" <gil.guerillot_at_ratp.fr> a écrit dans le message news: 9npnkj$5k7$1_at_gotix.reseau.ratp...
> but i want 4 cols (C1 and C2 on the same row)
>
>
>
> Romaniuk Igor <I.Romaniuk_at_upc.kiev.ua> a écrit dans le message :
> 1000366010.191132_at_upc-dot.upc.intranet...
> > It's possible to obtain results from 2 queries in one result table
> > when you use UNION ALL (or UNION):
> >
> > SELECT evt_code col1, TO_CHAR(evt_completed, 'mm') col2, COUNT(*) col3
> > FROM t1
> > WHERE evt_completed BETWEEN :begindate_param
> > AND
:enddate_param
> > AND status='C'
> > GROUP BY evt_code, TO_CHAR(evt_completed, 'mm')
> > UNION ALL
> > SELECT evt_code, TO_CHAR(evt_target, 'mm'), COUNT(*)
> > FROM t1
> > WHERE evt_target < :begindate_param
> > AND status='A'
> > GROUP BY evt_code, TO_CHAR(evt_target, 'mm');
> >
> >
> >
> > gil guerillot <gil.guerillot_at_ratp.fr> wrote in message
> > news:9nnsfo$3va$1_at_gotix.reseau.ratp...
> > > i have 2 select queries with different 'where and group by clauses'
> > > i'd like only one select to obtain something like that: select
> > > evt_code,to_char(EVT_COMPLETED,'mm'),C1,C2.....
> > >
> > >
> > > Q1
> > > select evt_code,to_char(EVT_COMPLETED,'mm'),count(*) C1
> > > from T1
> > > where EVT_COMPLETED between :begindate_param and :enddate_param
> > > and status='C'
> > > group by EVT_code, to_char(EVT_COMPLETED,'mm')
> > >
> > > Q2
> > > select evt_code,to_char(EVT_target,'mm'),count(*) C2
> > > from T1
> > > where EVT_target < :begindate_param
> > > and status='A'
> > > group by EVT_code, to_char(EVT_target,'mm')
> > >
> > >
> > >
> > >
> > > is it possible with SQL?
> > >
> > >
> >
> >
>
>
Received on Thu Sep 13 2001 - 03:28:07 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US