Help to write query(urgent)

Hi There,
I have 2 tables ''transaction" with column 'po_num' and ''purchase_order'' with columns 'po_num_id' and 'po_num_name'.
columns 'po_num' and 'po_num_name' have some numbers
some values in 'po_num_name' are equal to 'po_num' and some values are different
i want to uppend the transaction table with the values which are not equal to both columns(po_num and po_num_name)
means all the values should be included from po_num and those values should be included from po_num_name which are not same to po_num
please help me

ok
po_num contains more then 1 mill. records some of then are as :- and po_num_name contains 686 records
PO_Num
4500054039
4500053953
4500053952
4500053952
4500053952
4500053952
4500053952
4500053952
4500053952
4500053585
4500053580
4500053576
4500053500
4500053254
4500053249
4500053206
4500053079
4500053079
4500053077
4500053066
4500053029
4500053029
4500053028
4500053028
4500053021
4500053021
4500053021
4500053021
4500053017
4500053017
4500053016
4500053016
4500053015
4500053015
4500053013
4500053013
4500053012
4500053012
4500053011
4500053010
4500053010
4500053009
4500053009
4500053009
4500053009
4500053007
4500053006
4500053005
4500053005
4500053005
4500052998
4500052997
4500052997
4500052997
4500052997
4500052997
4500052997
4500052995
4500052995
4500052995
4500052995
4500052994
4500052994
4500052994
4500052994
4500052993
4500052993
4500052993
4500052993
4500052992
4500052992
4500052992
4500052992
4500052992
4500052991
4500052991
4500052991
4500052990
4500052990
4500052989
4500052989
4500052989
4500052989
4500052988
4500052988
4500052988
4500052988
4500052987
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052986
4500052985
4500052985
4500052985
4500052985
4500052954
4500052951
4500052951
4500052951
4500052950
4500052950
4500052950
4500052950
4500052950
4500052950
4500052949
4500052949
4500052949
4500052949
4500052949
4500052949
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
4500052948
po_num_name
No Purchase Order
Purchase Order Raised
4500014981
4500028176
4500033516
4500038270
4500038638
4500040360
4500042821
4500043038
4500043971
4500045298
4500045410
4500045535
4500045571
4500045573
4500045916
4500046085
4500046126
4500046129
4500046294
4500046791
4500046792
4500046975
4500047162
4500047276
4500047286
4500047373
4500047541
4500047745
4500047953
4500047956
4500047964
4500047968
4500047973
4500048464
4500048694
4500048859
4500048860
4500048902
4500049115
4500049117
4500049234
4500049241
4500049429
4500049433
4500049435
4500049445
4500049446
4500049476
4500049722
4500049823
4500049824
4500049872
4500049909
4500049967
4500049968
4500050059
4500050098
4500050177
4500050178
4500050179
4500050206
4500050209
4500050212
4500050213
4500050296
4500050431
4500050486
4500050506
4500050558
4500050559
4500050560
4500050779
4500050780
4500050961
4500050964
4500050966
4500051003
4500051007
4500051014
4500051019
4500051063
4500051065
4500051076
4500051077
4500051078
4500051092
4500051111
4500051125
4500051126
4500051128
4500051168
4500051169
4500051170
4500051223
4500051229
4500051264
4500051272
4500051304
4500051306
4500051307
4500051320
4500051323
4500051328
4500051336
4500051338
4500051340
4500051341
4500051342
4500051343
4500051344
4500051345
4500051348
4500051349
4500051350
4500051351
4500051353
4500051357
4500051360
4500051361
4500051362
4500051365
4500051366
4500051367
4500051368
4500051382
4500051392
4500051393
4500051394
4500051395
4500051397
4500051398
4500051401
4500051405
4500051406
4500051412
4500051483
4500051484
4500051604
4500051607
4500051669
4500051678
4500051679
4500051685
4500051700
4500051749
4500051778
4500051790
4500051791
4500051826
4500051832
4500051835
4500051836
4500051838
4500051866
4500051867
4500051872
4500051873
4500051874
4500051875
4500051876
4500051878
4500051879
4500051880
4500051881
4500051882
4500051883
4500051884
4500051885
4500051886
4500051890
4500051891
4500051892
4500051893
4500051894
4500051969
4500051970
4500052003
4500052004
4500052005
4500052006
4500052033
4500052034
4500052036
4500052037
4500052038
4500052047
4500052053
4500052054
4500052055
4500052056
4500052057
4500052059
4500052060
4500052061
4500052114
4500052117
4500052119
4500052120
4500052121
4500052122
4500052123
4500052124
4500052125
4500052126
4500052127
4500052128
4500052129
4500052130
4500052131
4500052136
4500052139
4500052148
4500052149
4500052150
4500052151
4500052176
4500052178
4500052180
4500052181
4500052182
4500052206
4500052207
4500052208
4500052210
4500052211
4500052212
4500052213
4500052214
4500052215
4500052268
4500052269
4500014808
4500014982
4500015176
4500015287
4500015290
4500015318
4500015319
4500015320
4500015616
4500015617
4500018275
4500018522
4500018523
4500018524
4500018525
4500024870
4500033258
4500033986
4500033987
4500033990
4500037030
4500037118
4500038550
4500038883
4500040898
4500042095
4500042143
4500042157
4500042598
4500042658
4500043226
4500044289
4500044640
4500045136
4500045145
4500045187
4500045311
4500045472
4500045657
4500045817
4500045837
4500045838
4500045840
4500045859
4500045978
4500046128
4500046278
4500046510
4500046511
4500046564
4500046972
4500046973
4500047336
4500047345
4500047369
4500047626
4500047659
4500047742
4500047760
4500047816
4500047859
4500047913
4500047923
4500047942
4500047950
4500047952
4500047965
4500048024
4500048025
4500048026
4500048119
4500048142
4500048334
4500048502
4500048523
4500048578
4500048630
4500048691
4500048729
4500048730
4500048779
4500048845
4500048846
4500048856
4500048940
4500048960
4500048990
4500048991
4500049109
4500049112
4500049113
4500049120
4500049160
4500049162
4500049164
4500049223
4500049228
4500049231
4500049232
4500049240
4500049295
4500049371
4500049432
4500049434
4500049444
4500049475
4500049480
4500049486
4500049554
4500049599
4500049649
4500049682
4500049686
4500049687
4500049718
4500049719
4500049721
4500049723
4500049724
4500049727
4500049764
4500049779
4500049780
4500049781
4500049782
4500049783
4500049784
4500049785
4500049786
4500049789
4500049818
4500049819
4500049820
4500049821
4500049822
4500049844
4500049870
4500049919
4500049920
4500049921
4500049922
4500049941
4500049942
4500049950
4500049951
4500049952
4500049953
4500049964
4500049966
4500049969
4500049971
4500049972
4500049986
4500049989
4500049991
4500050099
4500050156
4500050165
4500050170
4500050172
4500050173
4500050203
4500050204
4500050205
4500050210
4500050211
4500050214
4500050215
4500050224
4500050225
4500050226
4500050227
4500050298
4500050303
4500050324
4500050325
4500050326
4500050327
4500050328
4500050334
4500050407
4500050411
4500050412
4500050413
4500050414
4500050415
4500050416
4500050452
4500050457
4500050458
4500050487
4500050504
4500050505
4500050520
4500050523
4500050530
4500050556
4500050557
4500050562
4500050565
4500050615
4500050663
4500050692
4500050746
4500050750
4500050762
4500050768
4500050769
4500050770
4500050771
4500050773
4500050774
4500050775
4500050781
4500050782
4500050783
4500050784
4500050785
4500050789
4500050790
4500050812
4500050813
4500050814
4500050815
4500050816
4500050817
4500050818
4500050820
4500050847
4500050848
4500050849
4500050859
4500050860
4500050903
4500050938
4500050955
4500050957
4500050963
4500050965
4500051000
4500051001
4500051005
4500051006
4500051015
4500051022
4500051043
4500051044
4500051045
4500051046
4500051047
4500051093
4500051094
4500051136
4500051219
4500051232
4500051233
4500051234
4500051235
4500051265
4500051271
4500051300
4500051301
4500051319
4500051321
4500051322
4500051331
4500051334
4500051352
4500051354
4500051403
4500051404
4500051407
4500051422
4500051460
4500051461
4500051462
4500051485
4500051644
4500051680
4500051684
4500051747
4500051748
4500051750
4500051839
4500051851
4500052177
4500052183
4500052682
4500052270
4500052317
4500052319
4500052346
4500052347
4500052348
4500052350
4500052404
4500052406
4500052407
4500052408
4500052409
4500052445
4500052446
4500052455
4500052458
4500052513
4500052514
4500052515
4500052536
4500052537
4500052538
4500052540
4500052543
4500052566
4500052567
4500052570
4500052571
4500052572
4500052573
4500052574
4500052575
4500052577
4500052578
4500052579
4500052580
4500052583
4500052584
4500052585
4500052586
4500052587
4500052588
4500052616
4500052622
4500052623
4500052624
4500052630
4500052635
4500052636
4500052637
4500052638
4500052639
4500052641
4500052648
4500052662
4500052681
4500052684
4500052685
4500052727
4500052731
4500052737
4500052739
4500052743
4500052744
4500052745
4500052746
4500052747
4500052767
4500052768
4500052769
4500052770
4500052781
4500052782
4500052783
4500052785
4500052788
4500052789
4500052790
4500052792
4500052793
4500052794
4500052795
4500052796
4500052797
4500052798
4500052799
4500052836
4500052837
4500052838
4500052839
4500052840
4500052841
4500052844
4500052848
4500052857
4500052858
4500052859
4500052860
4500052861
4500052862
4500052883
4500052884
4500052885
4500052887
4500052889
4500052893
4500052894
4500052896
4500052909
4500052911
4500052917
4500052918
4500052926
4500052930
4500052931
4500052932
4500052937
4500052939
4500052940
4500052943
4500052948
4500052949
4500052950
4500052951
4500052954
4500052985
4500052986
4500052987
4500052988
4500052989
4500052990
4500052991
4500052992
4500052993
4500052994
4500052995
4500052997
4500052998
4500053005
4500053006
4500053007
4500053009
4500053010
4500053011
4500053012
4500053013
4500053015
4500053016
4500053017
4500053021
4500053028
4500053029
4500053066
4500053077
4500053079
4500053206
4500053249
4500053254
4500053500
4500053576
4500053580
4500053585
4500053952
4500053953
4500054039

Similar Messages

  • Help with the query---urgent

    PROCEDURE Mktg_Obj_Cmpgn(p_attr_tbl_nm IN attr.attr_tbl_nm%TYPE,p_actn_cd IN chg_log.actn_cd%TYPE) IS
    v_tbl_nm varchar2(100);
    v_actn_cd varchar2(4);
    BEGIN
    v_tbl_nm := p_attr_tbl_nm;
    v_actn_cd := p_actn_cd;
    --dbms_output.put_line(v_tbl_nm);
    IF v_actn_cd = 'CRET' THEN
    SELECT to_clob(XMLELEMENT("requestmessage",XMLATTRIBUTES(xmlforest(
    seq_pblsh_rqst.nextval AS "publish_id")),
    XMLAGG(XMLELEMENT("campaign",XMLATTRIBUTES(XMLFOREST(chg.actn_cd AS "ACTION",
    pgm.program_idseq AS "parententityvalue",
    ent_sbsrb.ENT_ID AS "entid",
    pgm.campaign_idseq AS "campaignid",
    bus_unt.portfolio_subtype_id AS "campaignsegment",
    pgm_typ.pgm_type_nm AS "campaigntype",
    LKP.lookup_key_desc AS "campaignclass",
    pgm.editor_userid AS "campaignlastmodifiedby",
    pgm.edited_dtm AS "campaignlastmodifieddate",
    pgm.mkt_initv_proc_tx AS "campaignlink",
    ofr.offer_idseq AS "offerlink")))),
    XMLAGG(XMLELEMENT("PROCESSCODE", XMLATTRIBUTES(XMLFOREST(action as "link",PROGRAM.program_idseq AS "parententityvalue",
    ENT_SBSRB_ATTR.ent_id AS "entid"))))))AS "v_clob" into v_clob1
    FROM dual,
    chg_log chg,
    program pgm,
    ent_sbsrb_attr ent_sbsrb,
    business_unit bus_unt,
    program_type pgm_typ,
    offer ofr,
    (SELECT lookup_keyword,lookup_key_desc,lookup_type
    FROM lookup_key
    WHERE lookup_type = 'PRTFL_CMPGN_ID')LKP
    WHERE chg.attr_id = ent_sbsrb.attr_id
    and chg.parnt_ent_val_tx = to_char(pgm.program_idseq)
    and pgm.business_unit_idseq = bus_unt.business_unit_idseq
    and pgm.pgm_type_cd = pgm_typ.pgm_type_cd
    and ofr.program_idseq = pgm.program_idseq
    and pgm.pgm_cls_cd(+) = LKP.lookup_keyword;
    END IF;
    end Mktg_Obj_Cmpgn;
    I have this procedure within a package. v_clob1 is declared in packagebody as a CLOB variable. when i try to compile it i am getting the below given error.can anyone please help me?
    (1): PL/SQL: ORA-19208: parameter 1 of function XMLELEMENT must be aliased
    (2): PL/SQL: SQL Statement ignored

    hi sir,
    wanna ask u guyz one query
    let say i have table name account(parent) and service(child)
    account
    id name status
    1 john 0
    2 ki 1
    3 kdf 2
    service
    id trans_id name status
    1 1 et 9999
    1 2 eee 2222
    2 3 ere 999
    2 4 wew 0
    i plan to use something like this
    delete account from account t1,service t2 where t1id=t2.id and t1.status<>0;
    but sql command not correct so plz help me
    now i need a query to delete records from service table only but
    account.status <> 0 and accound.id=service.id
    i dunt want to delete record from account table
    so can u help me with this query
    thanks
    Message was edited by:
    mani_um

  • Help to write query

    Hi,
    I have 4 tables inst_for_load(with column ins),word1(with columns w1 and id1),word2(with columns w2 and id2),word3(with columns w3 and id3)
    table inst_for_load has 10 million records.
    now when i m executing following query its taking 5 to 6 hr
    create table all_match as select ins,w1,w2,w3,id1,id2,id3 from inst_for_load,word1,word2,word3 where
    ins like '%'||word1.w1||'%' and
    ins like '%'||word2.w2||'%' and
    ins like '%'||word3.w3||'%'
    i have also created indexes for all tables.bt it doesn't word
    please help me
    Thanks

    i think the efficiency problem is bcoz of the " like " coz it will compare every character in those tables, and join condition in such manner is always slow. You need to filter it more. what if u try using upper or lower
    in where clause e.g,. upper(ins) like '%'||upper(word1.w1)||'%'
    Hey try executing this query coz i used it like that in my module including multiple tables and also calculations, it turned out to be really fast and accurate.
    select a.ins,b.w1,c.w2,d.w3,b.id1,c.id2,d.id3 from
    (select ins from inst_for_load) a,
    (select w1,idl from word1) b,
    (select w2,id2 from word2) c,
    (select w3,id3 from word3) d
    where upper(a.ins) like '%'||upper(b.w1)||'%'
    and upper(a.ins) like '%'||upper(c.w2)||'%'
    and upper(a.ins) like '%'||upper(d.w3)||'%'
    u can fix the query as u like , it is a desperate attempt and i hope it works for u. Most of the processing also depends on the machine too

  • Help to write query to get records from specified time TO specified time?

    I have a table which has large data and the table is updated every min,
    Suppose the Table comp(timeid date,sessions varchar2,sid varchar2)
    Here time needs to be checked
    So now i have to write a query which displays records that have been in the table
    for every 5 mins
    default timeframe is sysdate-5 then the lower and upper bound is multiple of 5 i.e
    Suppose now Time and sysdate: 12-sep-2007 1:22:00pm
    From sysdate: 12-sep-2007 1:15:01pm TO sysdate: 12-sep-2007 1:20:00pm
    So i need a query to get the records from 1:15:01pm to 1:20pm.
    Message was edited by:
    user594721

    Explanation is not clear.Please give sample data and expected o/p.
    If you need the data of previous five minutes, do like this...
    SQL> select id, to_char(time,'dd/mm/yyyy hh:mi:ss') time
      2  from test;
            ID TIME
             1 13/09/2007 10:29:55
             1 13/09/2007 10:29:22
             1 13/09/2007 10:20:28
    SQL> select id, to_char(time,'dd/mm/yyyy hh:mi:ss') time,
      2             to_char(sysdate,'dd/mm/yyyy hh:mi:ss') current_time
      3  from test
      4  where time between (sysdate - (5/24/60)) and sysdate;
            ID TIME                CURRENT_TIME
             1 13/09/2007 10:29:55 13/09/2007 10:32:45
             1 13/09/2007 10:29:22 13/09/2007 10:32:45                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help to write query

    Hi
    I have following table structure
    Name Type
    HOSTNAME VARCHAR2(30)
    COL1 VARCHAR2(30)
    COL2 VARCHAR2(30)
    data inthe table is like this
    HOSTNAME COL1          COL2
    H1               Authorized          Allowed
    H1               Authorized          Allowed
    H1               Authorized          Allowed
    H2               UnAuthorized     Denied
    H3               UnAuthorized     Denied
    H4               Authorized          Denied
    Now what i want is a query which will give count of Authorized, Unauhorized from col1
    and Count of Denied from col2
    output would look like this
    Authorized 4
    Unauthorized 2
    Denied     3
    Thanks in Advance,
    Kuldeep

    what did you try?
    WITH T AS
              (SELECT 'H1' hostname,'Authorized' col1 ,'Allowed'col2  FROM dual
                   UNION ALL
              SELECT 'H1', 'Authorized' ,'Allowed'    FROM dual
                   UNION ALL
              SELECT 'H1', 'Authorized', 'Allowed'      FROM dual
                   UNION ALL
              SELECT  'H2', 'UnAuthorized', 'Denied'    FROM dual
                   UNION ALL
              SELECT 'H3', 'UnAuthorized', 'Denied'     FROM dual
                   UNION ALL
              SELECT  'H4' ,'Authorized' ,'Denied'  FROM dual
    --- end of data               
    SELECT col1,ct
    FROM (SELECT col1,COUNT(*)ct FROM T GROUP BY col1
           UNION
            SELECT col2,COUNT(DECODE(col2,'Denied',1)) FROM T GROUP BY col2)
    WHERE ct>0

  • Hi!!Pls help !!Query Urgent!!

    Hi  all
    We have a ABC classification with respect to the char.ABC class  based on the Total Vlaue(New Query),
    We have already created with Analysis Processs designer based on the Shopping cart value(orginal Query) & they have restricted in the (orginal Query) too.
    TOTAL VALUE CODING:
    IF <result_fields>-/bic/ztotal_it > 30000000.
            <result_fields>-abc_class = 'A'.
          ELSEIF <result_fields>-/bic/ztotal_it BETWEEN 10000001 AND
          30000000.
            <result_fields>-abc_class = 'B'.
          .    ENDLOOP.
    My question to clarify is that do I have to change the restricted char with Shopping cart values(orginal Query) to my present TOTAL VALUE(New Query),.
    But if suppose I am changing it in TOTAL VALUE(New Query), ,it will reflect the Shopping cart values (Original query) also as it has been copied frm the original query.
    pls anyone revert to me ASAP.
    thnx IN ADVANCE

    Hi
    We are calculating the total Value based on char ABC classification like the following:
    IF ztotal_it  > 30000000.
    _class = 'A'.
    ELSEIF ztotal_it BETWEEN 10000001 AND 30000000.
    abc_class = 'B'.
    I have created this ,not sure whether this is correct,I have found in the query,some calculated key figures r used,So i want to know do i have to change the calculated key figure also, as I am not getting any data while executing in RSRT.
    Leave my previous question...
    pls clarify me this anyone & tell whether the routine is right & it has to be end routine or start routine???

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • Urgent Help:Tree structured query

    Hi,
    My requirement is as follows..
    I have two tables let's say A and B
    Table A has two fileds ID and PARENT_ID
    ID is a primary key and Parent_id is a foreign key to the same tables "ID" field(i.e, parent_id references a.id)
    Table B has 2 fields : status and id
    where ID is a foreign key to table A.id(B.id references A.ID)
    The data in those two tables looks like this
    A
    ID PARENT_ID
    1 2
    2 3
    3 4
    4
    5 6
    6 7
    7
    Table B has ..
    Status id
    Approved 1
    Approved 2
    Now I would like to select all the Approved Ids and all parent_IDs
    So i should get the following result
    id
    1
    2
    3
    4
    Can somebody help me write this query.. this is Kinda urgent Please.
    Thank you

    sql>select * from a;
           ID PARENT_ID
            1         2
            2         3
            3         4
            4
            5         6
            6         7
            7
    7 rows selected.
    sql>select * from b;
    STATUS                                ID
    Approved                               1
    Approved                               2
    2 rows selected.
    sql>select distinct id
      2    from a
      3   start with id in (select id
      4                       from b
      5                      where status = 'Approved')
      6   connect by prior parent_id = id;
           ID
            1
            2
            3
            4
    4 rows selected.

  • Need a help to write the query

    Hi,
    I need a small help to write the query.
    I have a table contains couponid,coupon,createdate,expirationdate,assigndate from couponday table
    i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.
    Thanks in advance

    Hi,
    user586 wrote:
    i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.If you mean expirationdate (datatype: DATE) is not within 30 days (past or future) of run time, then:
    SELECT  coupon          -- or whatever columns you want
    FROM    table_x
    WHERE   expirationdate  NOT BETWEEN  SYSDATE - 30
                                AND      SYSDATE + 30
    ;

  • Need urgent help with the query - Beginer

    Hello - I need help with a query to populate data in a table.Here is the scenario.
    Source1
    MnthID BranchCod CustID SegCode FXStatus ProfStatus Profit
    200712 B1 C1 20 Y Y 100
    Source2
    MnthID BranchCod CustID ProdCode ProdIndex
    200712 B1 C1 12 1
    200712 B1 C2 12 0
    Destination
    MnthID BranchCod SegCode ProdCode CountSegCust CountProdCust ProfitProdCust
    Condition and Calculations:
    1)Source1 customer are base customers.If Source2 has customers who is not in source1 then that customer's record should not be fetched.
    2)SegCode, FX Status, ProfStatus is one variable in destination table. [ SegCode = SegCode+ FXStatus (if FXStatus = Y)+ ProfStatus (if FXStatus = Y) ]
    3)CountSegCust = CountCustID Groupby MnthID,BranchCod,SegCode Only.
    4)CountProdCust = CountCustID Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
    5)ProfitProdCust = Sum of Profit of Customers Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
    Apologies for bad formatting.
    Thanks in advance!!

    A total guess indeed.
    It's not clear whether some aggregation can be done (summing counts of grouped data might cause some customers being counted more than once)
    insert into destination
    select mnthid,branchcod,segcode,prodcode,countsegcust,countprodcust,profitprodcust
      from (select s1.mnthid,
                   s1.branchcod,
                   s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end segcode,
                   s2.prodcode,
                   count(s1.custid) over (partition by s1.mnthid,
                                                       s1.branchcod,
                                                       s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                              order by null
                                         ) countsegcust,
                   count(case proindex when 1
                                       then custid
                         end
                        ) over (partition by s1.mnthid,
                                             s1.branchcod,
                                             s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                             s2.prodcode
                                    order by null
                               ) countprodcust,
                   sum(case proindex when 1
                                     then profit
                       end
                      ) over (partition by s1.mnthid,
                                           s1.branchcod,
                                           s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                           s2.prodcode
                                  order by null
                             ) profitprodcust,
                   row_number() over (partition by s1.mnthid,
                                                   s1.branchcod,
                                                   s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                                   s2.prodcode
                                          order by null
                                     ) the_row
              from source1 s1,source2 s2
             where s1.mnthid = s2.mnthid
               and s1.branchcod = s2.branchcod
               and s1.custid = s2.custid
    where the_row = 1Regards
    Etbin

  • Need helping in writing query for finding percentage of duration

    Can any one please help in writing query for this.
    The table is like this :-
    ID     Region     Month     Duration
    I1 R1     Jan     80
    I2     R2     Jan     70
    I3     R1     Jan     70
    I4     R3     Jan     40
    I5     R1     Feb     80
    I6     R2     Feb     30
    I7     R3     Mar     100
    I want to write a query to find
    % of duration for each and every region against each and every month.
    Please help in solving this query. I am in urgent need of this.
    Thanks in advance.

    I also have to do in MS Access 2003You also have to ask into an other forum since here it's an Oracle forum, to try to find Oracle solution.
    Nicolas.

  • What to write query to get know if a checkbox is checked

    hello,
    I have created a checkbox with name Entertainment containing static values Movie,Play,music.
    Now i have to write query to check which value of checkbox is checked ,means play or movie or music.
    According to that i have to mail a particular link to a user.
    I have seen in how to (checkbox help) but not getting it.
    please anyone can help me out.

    HI marc,
    I think so u are not able to get my problem,i will explain it in detail.
    I have a table USERINFO which has variables of type varchar2,these variable are used as a checkbox on page name 'ENTER INFORMATION',these checkbox have some static values,every time a user checks checkbox values it get stored in database,suppose there is a checkbox name sport with static values cricket,football,now if any user select cricket this value get stored in database with username ,mailid.
    Now i have a page on this i want to give user facility to enter name of checkbox to create and its corresponding static values,and these checkbox should get display on page 'ENTER INFORMATION'and a variable of type varchar2() with checkbox name should get create in tableUSERINFO .
    now can u suggest me how can i achieve this.

  • Help with my query

    Hello all,
    Total newbie to this pl/sql stuff. So, deseperately need help in my query.
    BOOKING_ID     BOOKING_STATUS     BOOKING_DATE     BOOKING_TIME     BOOKING_DATE_TIME
    1234567     CANCELLED     20090301     37252     5/1/2010 10:20
    1234567     CANCELLED 20090301     44229     5/1/2010 12:17
    1234567     BOOKED     20090301     39462     5/1/2010 10:57
    1234567     CANCELLED     20090301     43549     5/1/2010 12:05
    9671111     BOOKED     20090301     68124     5/1/2010 12:57
    9671111     CANCELLED     20090301     45001     5/1/2010 12:05
    How do I write my query such that I would get the following results:
    BOOKING_ID     BOOKING_STATUS     BOOKING_DATE     BOOKING_TIME     BOOKING_DATE_TIME
    9671111     BOOKED     20090301     68124     2/4/2010 12:17
    Basically, I am looking at the latest BOOKING_TIME and making sure the BOOKING_STATUS=BOOKED, if not, don't even bother bring back the result. Hence, you see that BOOKING_ID=1234567 is not required since at the latest BOOKING_TIME=44229, the BOOKING_STATUS=CANCELLED.
    Any help is greatly appreciated.
    Thank you in advance for your help.
    Stanley Ho

    Hi, Stanley,
    Welcome to the forum!
    Whenever you have a question, please post your sample data in a form that people can actually use. CREATE TABLE and INSERT statements are perfect.
    For example:
    CREATE TABLE     booking
    (     booking_id          NUMBER (8)
    ,     booking_status          VARCHAR2 (10)
    ,     booking_date_time     DATE
    INSERT INTO  booking (booking_id, booking_status, booking_date_time)
                  VALUES (1234567,        'CANCELLED',        TO_DATE ('5/1/2010 10:20', 'MM/DD/YYYY HH24:MI'));
    INSERT INTO  booking (booking_id, booking_status, booking_date_time)
                  VALUES (1234567,        'CANCELLED',        TO_DATE ('5/1/2010 12:17', 'MM/DD/YYYY HH24:MI'));
    INSERT INTO  booking (booking_id, booking_status, booking_date_time)
                  VALUES (1234567,        'BOOKED',        TO_DATE ('5/1/2010 10:57', 'MM/DD/YYYY HH24:MI'));
    INSERT INTO  booking (booking_id, booking_status, booking_date_time)
                  VALUES (1234567,        'CANCELLED',        TO_DATE ('5/1/2010 12:05', 'MM/DD/YYYY HH24:MI'));
    INSERT INTO  booking (booking_id, booking_status, booking_date_time)
                  VALUES (9671111,        'BOOKED',        TO_DATE ('5/1/2010 12:57', 'MM/DD/YYYY HH24:MI'));
    INSERT INTO  booking (booking_id, booking_status, booking_date_time)
                  VALUES (9671111,        'CANCELLED',        TO_DATE ('5/1/2010 12:05', 'MM/DD/YYYY HH24:MI'));What you want is called a Top-N Query .
    Here's one way to do it:
    WITH     got_rnum  AS
         SELECT     booking.*
         ,     ROW_NUMBER () OVER ( PARTITION BY  booking_id
                                   ORDER BY          booking_date_time     DESC
                           ) AS rnum
         FROM    booking
    SELECT     booking_id
    ,     booking_status
    ,     TO_CHAR (booking_date_time, 'YYYYMMDD')               AS booking_date
    ,     TO_CHAR (booking_date_time, 'SSSSS')               AS booking_time
    ,     TO_CHAR (booking_date_time, 'MM/DD/YYYY HH24:MI')     AS booking_date_time
    FROM     got_rnum
    WHERE     rnum          = 1
    AND     booking_status     = 'BOOKED'
    ;Notice that you don't need PL/SQL to do this; plain old SQL is good enough.
    Of course, if you're using PL/SQL for other reasons, you can use a query like this within PL/SQL.
    Dates (including time of day) should always be stored in DATE columns.
    If you have a DATE column, like booking_date_time, then there's no need for redundant date and time columns.
    You can always display just the year-month-day, or just the time, in any format, as I did above.
    The output from the query above, with the data above, is:
    BOOKING_ID BOOKING_ST BOOKING_ BOOKI BOOKING_DATE_TIM
       9671111 BOOKED     20100501 46620 05/01/2010 12:57I realize the booking_date and booking_time columns aren't quite what you posted. If they are not derivable from booking_date_time, then you probably do need separate columns for them, and those columns can easily be added to the query above.
    Edited by: Frank Kulash on Feb 5, 2010 4:41 PM
    KEEP (DENSE_RANK ...) , like Max used below, is a great tool to have in your kit. The problem with it is that you have to repeat a lot of stuff for every column, so the more columns you have in your output, the more tedious it gets. ROW_NUMBER sclaes much better, and is adaptable to more situations. I suggest you master ROW_NUMBER first, and look into KEEP (DENSE_RANK ...) later.

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Need help writing a query for following scenario

    Hi all, I need some help writing a query for the following case:
    One Table : My_Table
    Row Count: App 5000
    Columns of Interest: AA and BB
    Scenario: AA contains some names of which BB contains the corresponding ID. Some
    names are appearing more than once with different IDs. For example,
    AA BB
    Dummy 10
    Me 20
    Me 30
    Me 40
    You 70
    Me 50
    Output needed: I need to write a query that will display only all the repeating names with their corresponding IDs excluding all other records.
    I would appreciate any input. Thanks

    Is it possible to have a records with the same values for AA and BB? Are you interested in these rows or do you only care about rows with the same value of AA and different BB?
    With a slight modification of a previous posting you can only select those rows that have distinct values of BB for the same value of AA
    WITH t AS (
    SELECT 'me' aa, 10 bb FROM dual
    UNION ALL
    SELECT 'me' aa, 20 bb FROM dual
    UNION ALL
    SELECT 'you' aa, 30 bb FROM dual
    UNION ALL
    SELECT 'you' aa, 30 bb FROM dual
    SELECT DISTINCT aa, bb
      FROM (SELECT aa, bb, COUNT(DISTINCT bb) OVER(PARTITION BY aa) cnt FROM t)
    WHERE cnt > 1;

Maybe you are looking for