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: gil guerillot <gil.guerillot_at_ratp.fr>
Date: Thu, 13 Sep 2001 09:39:06 +0100
Message-ID: <9npnkj$5k7$1@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:39:06 CDT

Original text of this message

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