Is this SQL possible?

Sorry guys I mis-pasted and I can't edit my post (FOUND THE EDIT), sorry about the mistake.... Here is the post, hopefully correctly this time.
I am using Analytical functions on a data set similar to this:
ID_VAL, IND_TYP, AMT
123, X, 500
123, X, 700
123, Y, 47
123, Y, 15
245, X, 32
What I want to return is this:
ID_VAL,
COUNT OF IND_TYP = 'X',
SUM OF AMT WHERE IND_TYP = 'X'
COUNT OF IND_TYP = 'Y',
SUM OF AMT WHERE IND_TYP = 'Y'
I want to return this query all in one row so the result would look like this:
123, 2, 1200, 2, 62
245, 1, 32, 0, 0
Right now I can only get them seperated:
123, X, 2, 1200
123, Y, 2, 62
245, X, 1, 32
Here is the basis of my sql:
select distinct
     IDU,
     VAL,
     count(*) OVER (PARTITION BY IDU, VAL) as CNT,
     sum(NUM) OVER (PARTITION BY IDU, VAL) as SUM_CNT
from (
select '123' IDU, 'X' VAL, 500 NUM from dual
union all
select '123', 'X', 700 from dual
union all
select '123', 'Y', 47 from dual
union all
select '123', 'Y', 15 from dual
union all
select '245', 'X', 32 from dual
Message was edited by:
gpalush
Message was edited by:
gpalush

analytics? why?
select id_val,
  sum( decode(ind_typ,'X',1,0) ) x_cnt,
  sum( decode(ind_typ,'X',amt,0) ) x_amt,
  sum( decode(ind_typ,'Y',1,0) ) y_cnt,
  sum( decode(ind_typ,'Y',amt,0) ) y_amt
from tab
group by id_val

Similar Messages

  • How to reduce execution time of this SQL?

    This SQL will output only 2 rows. I tried using hints (an index) but to no avail.
    http://www.freeimagehosting.net/uploads/cf214afcf1.jpg
    Or, is it NOT possible, limit of query optimization has reached?

    Rakesh jayappa wrote:
    Hi,
    Run the sql tuning advisory.
    Let me know recommendation.
    Kind Regards,
    Rakesh************************** Here is my tuning request **************************
    1.) The following SQL statement has been identified to perform poorly. It currently takes up to 12 seconds to execute, but it's supposed to take a second at most.
    This is the statement:
    select DISTINCT trunc(c.sst_post_date) as post_date
    from ac_t_sessn b , ac_t_ssntr c
    where
           b.ses_status = 0
              and b.ses_profit_center = c.sst_profit_center
              and b.ses_acct_year = c.sst_acct_year
              and b.ses_acct_period = c.sst_acct_period
              and b.ses_sessn_no = c.sst_sessn_no
       AND
             C.sst_post_mtd||C.sst_post_TYPE IN
           (SELECT Y.pst_post_mtd||Y.pst_post_type
            FROM ac_r_post_functions Y
           WHERE Y.pst_post_status IN (0,'2'))
    order by trunc(c.sst_post_date);It should return data from a table in a specific order.
    2.) The version of the database is Oracle9i Enterprise Edition Release *9.2.0.6.0*
    3.) These are the parameters relevant to the optimizer:
    UAT_UML@umltest>show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     1
    optimizer_features_enable            string      9.2.0
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_max_permutations           integer     2000
    optimizer_mode                       string      CHOOSE
    UAT_UML@umltest>show parameter db_file_multi
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     16
    UAT_UML@umltest>show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    UAT_UML@umltest>show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    UAT_UML@umltest>column sname format a20
    UAT_UML@umltest>column pname format a20
    UAT_UML@umltest>column pval2 format a20
    UAT_UML@umltest>select
      2             sname
      3           , pname
      4           , pval1
      5           , pval2
      6      from
      7           sys.aux_stats$;
    no rows selected4.) Here is the output of EXPLAIN PLAN:
    UAT_UML@umltest>select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation              |  Name                | Rows  | Bytes |TempSpc| Cost  |
    |   0 | SELECT STATEMENT       |                      |   454 | 22700 |       |  5391 |
    |   1 |  SORT UNIQUE           |                      |   454 | 22700 |       |  5072 |
    |   2 |   HASH JOIN            |                      | 69384 |  3387K|  2592K|  4478 |
    |   3 |    INDEX FAST FULL SCAN| INDX_AC_T_SESSN      |   110K|  1294K|       |   244 |
    |   4 |    HASH JOIN           |                      |   416K|    15M|       |  3877 |
    |   5 |     TABLE ACCESS FULL  | AC_R_POST_FUNCTIONS  |    23 |   253 |       |     2 |
    |   6 |     TABLE ACCESS FULL  | AC_T_SSNTR           |  1790K|    46M|       |  3866 |
    Note: cpu costing is off, PLAN_TABLE' is old version5.) Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    UAT_UML@umltest>set autotrace traceonly arraysize 100
    UAT_UML@umltest>
    UAT_UML@umltest>select DISTINCT trunc(c.sst_post_date) as post_date
      2  from ac_t_sessn b , ac_t_ssntr c
      3  where
      4  b.ses_status = 0
      5  and b.ses_profit_center = c.sst_profit_center
      6  and b.ses_acct_year = c.sst_acct_year
      7  and b.ses_acct_period = c.sst_acct_period
      8  and b.ses_sessn_no = c.sst_sessn_no
      9  AND
    10  C.sst_post_mtd||C.sst_post_TYPE IN (SELECT         Y.pst_post_mtd||Y.pst_post_type FROM ac_r_po
    st_functions Y
    11  WHERE Y.pst_post_status IN (0,'2'))
    12  order by trunc(c.sst_post_date);
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=5391 Card=454 Bytes=
              22700)
       1    0   SORT (UNIQUE) (Cost=5072 Card=454 Bytes=22700)
       2    1     HASH JOIN (Cost=4478 Card=69384 Bytes=3469200)
       3    2       INDEX (FAST FULL SCAN) OF 'INDX_AC_T_SESSN' (NON-UNIQU
              E) (Cost=244 Card=110433 Bytes=1325196)
       4    2       HASH JOIN (Cost=3877 Card=416304 Bytes=15819552)
       5    4         TABLE ACCESS (FULL) OF 'AC_R_POST_FUNCTIONS' (Cost=2
               Card=23 Bytes=253)
       6    4         TABLE ACCESS (FULL) OF 'AC_T_SSNTR' (Cost=3866 Card=
              1790555 Bytes=48344985)
    Statistics
              0  recursive calls
              0  db block gets
          42741  consistent gets
            171  physical reads
              0  redo size
            425  bytes sent via SQL*Net to client
            507  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              2  rows processed
    UAT_UML@umltest>DISCONNECT
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production6.) The TKPROF output snippet
    TKPROF: Release 11.2.0.1.0 - Development on Wed Oct 27 12:47:35 2010
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Trace file: umltest_ora_1604.trc
    Sort options: prsela  exeela  fchela 
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select DISTINCT trunc(c.sst_post_date) as post_date
    from ac_t_sessn b , ac_t_ssntr c
    where
    b.ses_status = 0
    and b.ses_profit_center = c.sst_profit_center
    and b.ses_acct_year = c.sst_acct_year
    and b.ses_acct_period = c.sst_acct_period
    and b.ses_sessn_no = c.sst_sessn_no
    AND
    C.sst_post_mtd||C.sst_post_TYPE IN (SELECT         Y.pst_post_mtd||Y.pst_post_type FROM ac_r_post_functions Y
    WHERE Y.pst_post_status IN (0,'2'))
    order by trunc(c.sst_post_date)
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      3.20       4.38        171      42741          0           2
    total        4      3.21       4.39        171      42741          0           2
    Misses in library cache during parse: 1
    Optimizer mode: CHOOSE
    Parsing user id: 445 
    Rows     Row Source Operation
          2  SORT UNIQUE
         24   HASH JOIN 
         11    INDEX FAST FULL SCAN OBJ#(62817) (object id 62817)
    2293715    HASH JOIN 
         31     TABLE ACCESS FULL OBJ#(67305)
    1790555     TABLE ACCESS FULL OBJ#(62828)
    alter session set sql_trace true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: 445 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        2      3.20       4.38        171      42741          0           2
    total        5      3.21       4.39        171      42741          0           2
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        2  user  SQL statements in session.
        0  internal SQL statements in session.
        2  SQL statements in session.
    Trace file: umltest_ora_1604.trc
    Trace file compatibility: 9.02.00
    Sort options: prsela  exeela  fchela 
           1  session in tracefile.
           2  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           2  SQL statements in trace file.
           2  unique SQL statements in trace file.
          51  lines in trace file.
          10  elapsed seconds in trace file. Any help would be greatly appreciated?

  • Whats wrong with this sql statement ??

    Hello all, I am trying to run the below query out of persheet(tanel poder) performance excel chart...but i get below error...db is on 9.2
    what is wrong with this sql statement ?
    http://blog.tanelpoder.com/2008/12/28/performance-visualization-made-easy-perfsheet-20-beta/
    select * from (
    with fsq as (
      select /*+ materialize */
       i.dbid
        , i.instance_name
        , i.instance_number
    --    , trunc(s.snap_time, 'DD')     DAY
    --    , to_number(to_char(s.snap_time, 'HH24'))  HOUR
    --   -- , to_char(s.snap_time, 'MI')    MINUTE
    --    , 0           MINUTE
        , trunc(
          lag(s.snap_time, 1)
          over(
           partition by
          v.dbid
           , i.instance_name
           , v.instance_number
           , v.event
         order by
          s.snap_time
          , 'HH24'
         )           SNAP_TIME
        , v.event_type        EVENT_TYPE
        , v.event          EVENT_NAME
        , nvl(
        decode(
         greatest(
          time_waited_micro,
          nvl(
           lag(time_waited_micro,1,0)
           over(
            partition by
             v.dbid
              , i.instance_name
              , v.instance_number
              , v.event
            order by v.snap_id
           , time_waited_micro
         time_waited_micro,
         time_waited_micro - lag(time_waited_micro,1,0)
         over (
          partition by
           v.dbid
            , i.instance_name
            , v.instance_number
            , v.event
          order by v.snap_id
         time_waited_micro
           , time_waited_micro
         ) / 1000000         SECONDS_SPENT
        , total_waits         WAIT_COUNT
      from
       (select distinct dbid, instance_name, instance_number from stats$database_instance) i
        , stats$snapshot s
        , ( select
         snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits
        from
         stats$system_event
        where
         event not in (select event from stats$idle_event)
        union all
        select
         snap_id, dbid, instance_number,
         case
          when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
          when name like 'OS % time' then 'OS'
          else 'STAT'
         end,
         name , value, 1
        from
         stats$sysstat
    --    where      name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
    --    or  name like('OS % time')
    --    or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
       ) v
      where
       i.dbid = s.dbid
      and i.dbid = v.dbid
      and s.dbid = v.dbid
      and s.snap_id = v.snap_id
      and s.snap_time between '%FROM_DATE%' and '%TO_DATE%'
      and i.instance_name = '%INSTANCE%'
    select * from (
      select
       instance_name
        , instance_number
        , snap_time
        , trunc(snap_time, 'DD')  DAY
        , to_char(snap_time, 'HH24') HOUR
        , to_char(snap_time, 'MI') MINUTE      
        , event_type  
        , event_name  
        , seconds_spent
        , wait_count  
        , ratio_to_report(seconds_spent) over (
    --      partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
          partition by (snap_time)
          ) ratio
      from fsq
      where
       snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
      -- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')
      -- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
    where ratio > 0
    order by
        instance_name
      , instance_number
      , day
      , hour
      , minute
      , event_type
      , seconds_spent desc
      , wait_count desc
    Error at line 6
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00972: identifier is too long

    Hi Alex,
    Subquery factoring a.k.a. the with-clause should be possible on 9.2:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2075888
    (used it myself as well on 9.2)
    @OP
    I recall having problems myself using PL/SQL Developer and trying to get the with clause to work on 9.2 some years ago.
    A workaround might be to create a view based on the query.
    Also, your error message is "ORA-00972: identifier is too long"...
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14219/e900.htm#sthref419
    Can't test things currently, no 9.2 available at the moment, but perhaps tomorrow I'll have a chance.

  • I don't know how I can optimize this SQL

    Dear ALL:
    I don't know how I can optimize this SQL.
    Is it possible to make a better SQL or PL/SQL?
    Please let me know your good thought.
    Thank you.
    Sincerely,
    ===========================================================
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('01:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    UNION ALL
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('01:00:01','HH24:MI:SS')
    AND TO_DATE('02:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    UNION ALL
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('02:00:01','HH24:MI:SS')
    AND TO_DATE('03:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    UNION ALL
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('03:00:01','HH24:MI:SS')
    AND TO_DATE('04:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    ORDER BY A ASC, B ASC, C ASC
    ===========================================================

    Dear Warren:
    Actually, for this query, it takes a few second to complete the query.
    But, I have to create several time period and I have to optimize the SQL.
    Time period is 1 hour, 30 min, 15 min, 5 min.
    That is,
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('01:00:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:00:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('00:30:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:30:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('00:15:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:45:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('00:05:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:55:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    Do you know how this SQL is optimized?
    Thank you,

  • How to rewrite this SQL statement

    I have tableA and tableB as below. The following query gets Max(Process_date) during month of january from the
    two tables tableA and tableB with different criteria
    I want to expand the following query to return  Max(Process_date) for BOTH current month(txn_date=entire jan2013) and prior month(txn_date= entire dec2013)
    Is it possible? If so how can I modify this query to return MAX(PROCESS_DATE) for current and prior months in single query.
    SELECT MAX(process_date)  AS curr_month_amount FROM
      SELECT process_date AS process_date,
             amount1 AS amount
      FROM   tableA
      WHERE  id = 1 AND
             process_date = (SELECT MAX(process_date)
                      FROM tableA
                     WHERE id = 1  and txn_date between TO_DATE('01-JAN-2013','dd-mon-yyyy') and TO_DATE('31-JAN-2013', 'dd-mon-yyyy')
            AND amount1 = 0
          UNION
      SELECT MAX(process_date) AS process_date,
             0 AS amount
      FROM   tableB
      WHERE id = 1 AND txn_code = 'B' and  txn_date between TO_DATE('01-JAN-2013','dd-mon-yyyy') and TO_DATE('31-JAN-2013', 'dd-mon-yyyy')
    future state of the sql
    Single sql statement a) should look at txn_date between 1/1/2013 - 1/31/2013 to return max(process_date) for current month
                         b) should look at txn_date between 12/1/2012 - 12/31/2012 to return max(process_date) for prior month
    NOTE:-( i want to pass current_month_end date 1/31/2013 to this sql so it will calculate for current and prior months)
    expected output
    ***************:   For id=1 in the modified query,
       prior month max(process_date) should be    1/19/2013
       current month max(process_date) should be   1/15/2012
         For id=5 in the modified query
       prior month max(process_date) should be   NULL
       current month max(process_date) should be  1/16/2013
    SQL to create TableA and TableB  with insert statements( txn_date column not included)
    CREATE table tableA
    id   NUMBER,
    process_date  DATE,
    amount1         NUMBER,
    txn_code VARCHAR2(1),
    txn_date DATE
    Create table tableB
    ( id  NUMBER,
    process_date DATE,
    amount2         NUMBER,
    txn_code VARCHAR2(1),
    txn_date DATE
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('01/12/2013','mm/dd/yyyy'), 500, 'A',  to_date('01/15/2013','mm/dd/yyyy')  );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('01/13/2013','mm/dd/yyyy'), 100, 'A',  to_date('01/14/2013','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code , txn_date)
    values
    ( 1, to_date('01/14/2013','mm/dd/yyyy'), 0, 'A',    to_date('01/15/2013','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 1, to_date('01/15/2013','mm/dd/yyyy'), 0, 'B', to_date('01/31/2013','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('12/01/2012','mm/dd/yyyy'), 500, 'A',  to_date('12/31/2012','mm/dd/yyyy')  );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code , txn_date)
    values
    ( 1, to_date('12/23/2012','mm/dd/yyyy'), 100, 'A',  to_date('12/14/2012','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('12/19/2012','mm/dd/yyyy'), 0, 'A',    to_date('12/15/2012','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 1, to_date('12/15/2012','mm/dd/yyyy'), 0, 'C', to_date('12/31/2012','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('01/11/2013','mm/dd/yyyy'), 500, 'A', to_date('01/09/2013','mm/dd/yyyy')    );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    (5, to_date('01/12/2013','mm/dd/yyyy'), 0, 'A', to_date('01/19/2013','mm/dd/yyyy'))
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('01/15/2013','mm/dd/yyyy'), 10 , 'A', to_date('01/09/2013','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 5, to_date('01/16/2013','mm/dd/yyyy'), 1, 'B', to_date('01/09/2013','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('12/11/2012','mm/dd/yyyy'), 500, 'A', to_date('12/09/2012','mm/dd/yyyy')    );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    (5, to_date('12/12/2012','mm/dd/yyyy'), 0, 'A', to_date('12/19/2012','mm/dd/yyyy'))
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('12/15/2012','mm/dd/yyyy'), 10 , 'A', to_date('12/09/2012','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 5, to_date('12/16/2012','mm/dd/yyyy'), 1, 'C', to_date('12/09/2012','mm/dd/yyyy'));
    commit;

    Maybe
    SELECT id,
           month,
           MAX(process_date) AS curr_month_amount
      FROM (SELECT id,
                   process_date AS process_date,
                   amount1 AS amount,
                   TO_CHAR(txn_date,'mm') AS month
              FROM tableA
             WHERE (process_date,TO_CHAR(txn_date,'mm')) in
                     (SELECT MAX(process_date),TO_CHAR(txn_date,'mm') 
                        FROM tableA
                       WHERE txn_date between ADD_MONTHS(TO_DATE('01-JAN-2013','dd-mon-yyyy'),-1)
                                          AND TO_DATE('31-JAN-2013','dd-mon-yyyy')
                         AND amount1 = 0
                       GROUP BY TO_CHAR(txn_date,'mm')
               AND amount1 = 0
            UNION
            SELECT id,
                   MAX(process_date) AS process_date,
                   0 AS amount,
                   TO_CHAR(txn_date,'mm') AS month
              FROM tableB
             WHERE txn_code = 'B'
               AND txn_date between ADD_MONTHS(TO_DATE('01-JAN-2013','dd-mon-yyyy'),-1)
                                AND TO_DATE('31-JAN-2013','dd-mon-yyyy')
             GROUP BY id,TO_CHAR(txn_date,'mm')
    GROUP BY id,month
    ID
    MONTH
    CURR_MONTH_AMOUNT
    5
    01
    01/16/2013
    1
    12
    12/19/2012
    1
    01
    01/15/2013
    Regards
    Etbin

  • Hi, I'd like to set alarms or reminders on my I phone or I pad so that it can update or sync automatically with each other. I don't know if this is possible or how to do it. I hope you can help..

    Hi, I'd like to set alarms or reminders on my I phone or I pad so that it can update or sync automatically with each other. I don't know if this is possible or how to do it. I hope you can help.

    HI, if I did this, then I believe that I cloud would then hold my info which I don't want. Is that the case? The reason is that I'm an old git, therefore used to not giving out info. Would I be right?
    Thank-You so much for taking the time to answer.
    John.

  • HT4436 I both have iCloud accounts and would like to share photo's etc. Can any one please advise if this is possible and how to do it?

    My wife and I both have iCloud accounts and would like to share photo's etc. Can any one please advise if this is possible and how to do it?      
    I have a Macbook-pro and Ipad, my wife has a much loved ipad.

    It's all described in iCloud Help here: http://help.apple.com/icloud/#mmc0cd7e99

  • I'm trying to find out how to export my apple contacts to the Salesforce software and they need to be in a csv format and I don't know if this is possible and how to do it if it is?

    I'm trying to find out how to export my apple contacts to the Salesforce software and they need to be in a csv format and I don't know if this is possible and how to do it if it is?

    I think there are third-party programs which will do that, but you can also do it with Automator:
    See the links in my post, here: https://discussions.apple.com/message/22390873#22390873
    The file or clipboard contents will be in Tab Separated vars, so you'll have to open with a spreadsheet program and save as Comma Separated Vars format.

  • I recently bought a new iMac as well as a wireless time capsule and have it connected how can I use this external drive as the location to store all my files for iTunes, or is this even possible?

    New iMac user here, I recently bought a new iMac and Time capsule and have the whole network up and running now. I have connected another external HD to the time capsule as well and have a total of 3 TB of storage connected wireless to my new iMac. My question is can I use this location as the default location for iTunes?  I doubt I am gonna run out of room considering the iMac has 1 TB of storage already, but I'd prefer to keep my movies and music off the Mac to keep it running smoothly. If this is possibly, I'd like to do this with iPhoto as well. 

    I would advise against placing your iTunes library on a Time Capsule.
    The Time Capsule is designed as a backup device and not for wireless streaming of video.
    Before you do anything more, can I suggest you put into place a reliable, redundant backup strategy.
    Unless you are prepared to risk loss of your iTunes library due to a hard drive failure, I would not put iTunes on the Time Capsule.
    Leave your iTunes library on your iMac until such time as your internal drive is full. Backup to Time Capsule using Time Machine and create a clone of your internal iMac HD to your external drive.
    That's my 2 cents worth. Others may have a different opinion.

  • MacBook Pro battery had accumulated more than a 1000 charges, and stopped functioning unexpectedly. Went and got the battery replaced. Just saw that SMC Firmware 1.6 update deals with this. Possible to get my money back?

    MacBook Pro battery had accumulated more than a 1000 charges, and stopped functioning unexpectedly. Went and got the battery replaced. Just saw that SMC Firmware 1.6 update deals with this. Possible to get my money back?

    The firmware update corrects an error that may occur, however the techs would have checked the condition of the battery prior to installing a new one.  If the battery was questionable, the firmware update was really not too important.
    You can check the battery condition by going to the apple, left side of the menu bar, About This Mac, More Info, System Report, Hardware, Power and see what it says about Cycle Count, Condition, Capacity: Condition anything but Normal needs to be checked and may need to be replaced.
    The cycle count of 1,000 charge cycles is the typical life of a Lithium-Ion battery, the point at which the capacity drops to 80% of the as built capacity.

  • How can i see when someone has accessed my call/text log. (This is possible on google) I have been informed that someone has accessed my activity log and is giving my information to a third party. I believe it is a service tech, but I am not interested in

    How can i see when someone has accessed my call/text log. (This is possible on google/gmail) I have been informed that someone has accessed my activity log and is giving my information to a third party. I believe it is a service tech, but I am not interested in persuing that further. I just need to see when my account has been accessed if possible.

    Hi lynniewigs,
    This is a common concern among Android and I-phone user, and one of the drawbacks to using a smart phone.  We lose so much privacy. Our phones become cameras into our homes for us to be spied on.
    I don't know what type of phone you have, if it is even a smart phone, but here is an example of an application that you can use to determine which applications are accessing your information and sending it out. 
    Permission Scanner - Android Apps on Google Play
    Google just recently revamp their permissions geared to hide invasive applications that spy and send out your information without your knowledge.  Report says be aware of what your Android app does - CNET
    Please continue to be mindful of the apps you download and the permissions you give. 

  • What's wrong with this SQL?

    what's wrong with this SQL?
    Posted: Jan 16, 2007 9:35 AM Reply
    Hi, everyone:
    when I insert into table, i use the fellowing SQL:
    INSERT INTO xhealthcall_script_data
    (XHC_CALL_ENDED, XHC_SWITCH_PORT, XHC_SCRIPT_ID, XHC_FAX_SPECIFIED)
    VALUES (SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS'), HH_SWITCHPORT, HH_SCRIPT,'N'
    FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE' UNION
    SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS'), HH_SWITCHPORT, HH_SCRIPT,'N' FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE');
    I always got an error like;
    VALUES (SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS'), HH_SWITCHPORT,
    ERROR at line 3:
    ORA-00936: missing expression
    but I can't find anything wrong, who can tell me why?
    thank you so much in advance
    mpowel01
    Posts: 1,516
    Registered: 12/7/98
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 9:38 AM in response to: jerrygreat Reply
    For starters, an insert select does not have a values clause.
    HTH -- Mark D Powell --
    PP
    Posts: 41
    From: q
    Registered: 8/10/06
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 9:48 AM in response to: mpowel01 Reply
    Even I see "missing VALUES" as the only error
    Eric H
    Posts: 2,822
    Registered: 10/15/98
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 9:54 AM in response to: jerrygreat Reply
    ...and why are you doing a UNION on the exact same two queries?
    (SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS') ,HH_SWITCHPORT ,HH_SCRIPT ,'N' FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE' UNION SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS') ,HH_SWITCHPORT ,HH_SCRIPT ,'N' FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE');
    jerrygreat
    Posts: 8
    Registered: 1/3/07
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 9:55 AM in response to: mpowel01 Reply
    Hi,
    thank you for your answer, but the problem is, if I deleted "values" as you pointed out, and then execute it again, I got error like "ERROR at line 3:
    ORA-03113: end-of-file on communication channel", and I was then disconnected with server, I have to relogin SQLplus, and do everything from beganing.
    so what 's wrong caused disconnection, I can't find any triggers related. it is so wired?
    I wonder if anyone can help me about this.
    thank you very much
    jerry
    yingkuan
    Posts: 1,801
    From: San Jose, CA
    Registered: 10/8/98
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 9:59 AM in response to: jerrygreat Reply
    Dup Post
    jerrygreat
    Posts: 8
    Registered: 1/3/07
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 10:00 AM in response to: Eric H Reply
    Hi,
    acturlly what I do is debugging a previous developer's scipt for data loading, this script was called by Cron work, but it never can be successfully executed.
    I think he use union for eliminating duplications of rows, I just guess.
    thank you
    jerry
    mpowel01
    Posts: 1,516
    Registered: 12/7/98
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 10:03 AM in response to: yingkuan Reply
    Scratch the VALUES keyword then make sure that the select list matches the column list in number and type.
    1 insert into marktest
    2 (fld1, fld2, fld3, fld4, fld5)
    3* select * from marktest
    UT1 > /
    16 rows created.
    HTH -- Mark D Powell --
    Jagan
    Posts: 41
    From: Hyderabad
    Registered: 7/21/06
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 10:07 AM in response to: jerrygreat Reply
    try this - just paste the code and give me the error- i mean past the entire error as it is if error occurs
    INSERT INTO xhealthcall_script_data
    (xhc_call_ended, xhc_switch_port, xhc_script_id,
    xhc_fax_specified)
    SELECT TO_DATE (hh_end_date || ' ' || hh_end_time, 'MM/DD/YY HH24:MI:SS'),
    hh_switchport, hh_script, 'N'
    FROM tmp_healthhit_load
    WHERE hh_script != 'BROCHURE'
    UNION
    SELECT TO_DATE (hh_end_date || ' ' || hh_end_time, 'MM/DD/YY HH24:MI:SS'),
    hh_switchport, hh_script, 'N'
    FROM tmp_healthhit_load
    WHERE hh_script != 'BROCHURE';
    Regards
    Jagan
    jerrygreat
    Posts: 8
    Registered: 1/3/07
    Re: what's wrong with this SQL?
    Posted: Jan 16, 2007 11:31 AM in response to: Jagan Reply
    Hi, Jagan:
    thank you very much for your answer.
    but when I execute it, I still can get error like:
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    so wired, do you have any ideas?
    thank you very much

    And this one,
    Aother question about SQL?
    I thought I already told him to deal with
    ORA-03113: end-of-file on communication channel
    problem first.
    There's nothing wrong (syntax wise) with the query. (of course when no "value" in the insert)

  • When using Firefox Sync on multiple devices, I used to be able to 'send' a tab from one computer to another. Is this still possible? If so, how?

    When using Firefox Sync on multiple devices, I used to be able to 'send' a tab from one computer to another. Is this still possible? If so, how?
    I don't mean the ability to see what tabs are open on another device (I know how to do this). But if I am at work and find something that I want to read at home, it would be helpful to 'send' the tab to my home PC so that when I return home, it will automatically open that tab for me.

    Can anyone help?

  • Is this a possible bug on the Facebook app for iPhone?

    I tend to suffer from slight paranoia regarding security online and on my phone. I'll try to explain the worry I'm having as best I can.
    Basically, I had a personal video on my phone, (nothing horrible don't worry), but it's of a nature that would be embarrassing to be seen by other people.
    So this video was the latest thing I had recorded/taken with my phone. I went onto the Facebook app on my iPhone to post an older picture I had to my page.
    When I saw that this video was still on my phone, I panicked and worried that it could somehow get posted to my page without me actually posting it e.g. a bug whereby the last picture or video taken would go onto your Facebook without you actually selecting it or posting it. So I deleted it while still on the grid page where you choose your photos/videos and so it disappeared when I went back to the app.
    Can anyone with 100% honesty tell me one way or another if this is possible? If I haven't explained it enough let me know and I'll explain it further. Again, please be honest cos it's the best thing for me. Thanks.

    It may be in Facebook, but Facebook doesn't consider it a bug; it's the way Facebook works. If you gave the app permission to view your photos it gives Facebook access to ALL of your photos. To put your mind at ease go to your Facebook page on your computer and see if it's there.
    If you are concerned about privacy online you probably shouldn't have a Facebook page

  • Is it possible to connect my 2008 black macbook, to my new 2014 macbook pro retina display screen to make a dual monitor. If this is possible what cables would I need to buy?

    Is it possible to connect my 2008 black macbook, to my new 2014 macbook pro retina display screen to make a dual monitor. If this is possible what cables would I need to buy?

    You can try using Screen Sharing in the Sharing preferences. Or try a third-party utility such as ScreenRecycler.

Maybe you are looking for

  • Steps to create a Universe based on Bex query

    HI Gurus, I am (first time ofcourse) creating a Universe based on a Bex Query. I searched on SDN to find steps to craete a universe on top of Bex query and found a document written by tej Trivedi and found other threads also which explains all the st

  • Audio CDs burnt off iTunes cannot be played

    This is a rather curious problem - when I burn an album I purchased in the iTunes store to a CD it subsequently fails to play not only on my CD player and DVD player, but also in iTunes itself - in this last case the CD is recognised by iTunes and th

  • Website Design Using Adobe Flash

    Hi everybody, I need some help from anyone that expert in website design using adobe flash player. Please send me a PM. Thank you Jarlabs

  • Create error journal

    Hello, I created a batch input for a transaction. When I do call transaction all error messages are stored in an internal table. What I want to do is, after the batch input is complete, to display a log with all errors stored in this table. I've noti

  • Portions of web pages are cut off unless I diminish zoom with my mouse control.

    Some portions of web pages are cut off