Help the query group

HII Guru

Please help me.

I have question

Select

HP.party_name as a customer,

RCT.trx_number like Bill,

RCT.trx_date,

rctl.attribute3 as Faktur_Pajak,

rctl.attribute4 as TIN,

rctl.line_number not,.

rctl. Description,

GCC. Segment1 |'. ' | GCC. Segment2 |'. ' | GCC.segment3 |'. ' | GCC.segment4 |'. ' | GCC.segment5 |'. ' | GCC.segment6 as COA,

rctl.extended_amount as long as dpp,.

rctl.extended_amount * avt.tax_rate / 100 / rctl.extended_amount * 100 as tax_rate,.

rctl.extended_amount * avt.tax_rate / 100 as NPP

Of

ra_customer_trx_lines_all rctl,

ra_customer_trx_all rct,

hz_cust_accounts AOB,

hz_parties hp,

ar_vat_tax_all_b avt,

gl_code_combinations gcc,

ar_memo_lines_all_b amb

where 1 = 1

and rct.org_id = "122"

and rct.trx_number = 'ExpressMay14.13143. '

and rctl.memo_line_id = amb.memo_line_id

and amb.gl_id_rev = gcc.code_combination_id

and hca.party_id = hp.party_id

and rct.customer_trx_id = rctl.customer_trx_id

and rct.sold_to_customer_id = hca.cust_account_id

and avt.vat_tax_id = rctl.vat_tax_id

and rctl.description is not null

and rct.trx_date BETWEEN TO_DATE('05/01/2014','MM/DD/YYYY') AND TO_DATE('05/07/2014','MM/DD/YYYY')

order of trx_date

and the result is

CUSTOMERINVOICETRX_DATEFAKTUR_PAJAKTINNO.DESCRIPTIONCOAGP3TAX_RATENPP
EVAGENITA, UDExpressMay14.131432 May 14040.001 - 14.8163714907.358.521.8 - 311,0001BKS-Express21.W10.544300.0000.000.0002 664 750126 648
EVAGENITA, UDExpressMay14.131432 May 14040.001 - 14.8163714907.358.521.8 - 311,0002Stamp duty21.000.807220.0000.000.0006 00000

actually I want to display as

CUSTOMERINVOICETRX_DATEFAKTUR_PAJAKTINNO.DESCRIPTIONCOAGP3TAX_RATENPPTotal
EVAGENITA, UDExpressMay14.131432 May 14040.001 - 14.8163714907.358.521.8 - 311,0001BKS-Express21.W10.544300.0000.000.0002 664 750126 648
2Stamp duty21.000.807220.0000.000.0006 000002 697 398
Consider the 

with t
as
(
...
)

As your actual query. You can do this.

SQL> with t
  2  as
  3  (
  4  select 'EVAGENITA, UD' customer
  5       , 'ExpressMay14.13143' invoice
  6       , to_date('2-May-14','dd-mon-rr') trx_date
  7       , '040.001-14.81637149' faktur_pajak
  8       , '07.358.521.8-311.000' npwp
  9       , 1 no
 10       , 'BKS-Express' description
 11       , '21.W10.544300.0000.000.000' coa
 12       , 2664750 dpp
 13       , 1 tax_rate
 14       , 26648 pnn
 15    from dual
 16  union all
 17  select 'EVAGENITA, UD' customer
 18       , 'ExpressMay14.13143' invoice
 19       , to_date('2-May-14','dd-mon-rr') trx_date
 20       , '040.001-14.81637149' faktur_pajak
 21       , '07.358.521.8-311.000' npwp
 22       , 2 no
 23       , 'Stamp Duty' description
 24       , '21.000.807220.0000.000.000' coa
 25       , 6000 dpp
 26       , 0 tax_rate
 27       , 0 pnn
 28    from dual
 29  )
 30  select decode(rno, 1, customer) customer
 31       , decode(rno, 1, invoice) invoice
 32       , decode(rno, 1, trx_date) trx_date
 33       , decode(rno, 1, faktur_pajak) faktur_pajak
 34       , decode(rno, 1, npwp) npwp
 35       , no
 36       , description
 37       , coa
 38       , dpp
 39       , tax_rate
 40       , pnn
 41       , case when
 42               rno = cnt then
 43                 sum
 44                 (
 45                    dpp+pnn
 46                 )
 47                 over
 48                 (
 49                   partition
 50                          by customer
 51                           , invoice
 52                           , trx_date
 53                           , faktur_pajak
 54                           , npwp
 55                       order
 56                          by no
 57                 )
 58         end total
 59    from (
 60            select t.*
 61                 , row_number() over
 62                                (
 63                                   partition
 64                                          by customer
 65                                           , invoice
 66                                           , trx_date
 67                                           , faktur_pajak
 68                                           , npwp
 69                                       order
 70                                          by no
 71                                ) rno
 72                 , count(*)     over
 73                                (
 74                                   partition
 75                                          by customer
 76                                           , invoice
 77                                           , trx_date
 78                                           , faktur_pajak
 79                                           , npwp
 80                                ) cnt
 81              from t
 82          );

CUSTOMER      INVOICE            TRX_DATE  FAKTUR_PAJAK        NPWP                         NO DESCRIPTION COA                               DPP   TAX_RATE        PNN      TOTAL
------------- ------------------ --------- ------------------- -------------------- ---------- ----------- -------------------------- ---------- ---------- ---------- ----------
EVAGENITA, UD ExpressMay14.13143 02-MAY-14 040.001-14.81637149 07.358.521.8-311.000          1 BKS-Express 21.W10.544300.0000.000.000    2664750          1      26648
                                                                                             2 Stamp Duty  21.000.807220.0000.000.000       6000          0          0    2697398

SQL>

Tags: Database

Similar Questions

  • Ask for help with the query group by

    Hello
    I have the following table with values structure
    CREATE TABLE DUMMY
      (
        SR_NUMBER          VARCHAR2(100 CHAR),
        ASSIGNMENT_GROUP   VARCHAR2(100 CHAR),
        REASSIGNMENT_COUNT VARCHAR2(100 CHAR),
        CREATED DATE,
        CLOSED DATE,
        TARGET_DATE DATE
     )
     
     insert into dummy values('AAA','A','1','02-OCT-11','25-OCT-11','09-OCT-11');
     insert into dummy values('ABC','A','1','03-SEP-12','26-SEP-11','10-SEP-11');
     insert into dummy values('AVB','A','1','02-NOV-13','25-NOV-13','09-NOV-13');
     insert into dummy values('AFT','B','1','02-OCT-11','25-OCT-11','09-OCT-11');
     insert into dummy values('ACS','B','1','02-JAN-12','25-JAN-12','09-JAN-12');
     insert into dummy values('AVC','B','1','02-OCT-13','25-OCT-13','09-OCT-13');
     insert into dummy values('AAD','B','1','02-MAR-14','25-MAR-14','09-MAR-14');
     insert into dummy values('AAA','C','1','02-OCT-11','25-OCT-11','09-OCT-11');
    insert into dummy values('AAA','D','1','02-JUN-11','25-JUN-11','09-JUN-11');
    insert into dummy values('AAA','E','1','02-APR-12','25-APR-12','09-APR-12');
    insert into dummy values('AAA','A','1','02-FEB-13','25-FEB-13','09-FEB-13');
    
    ?
    I have the following requirement, the output should be:

    Number of ticket (sr_number)
    % of tickets inside the DL
    Number of tickets inside the DL
    Average cycle time (cycle time = closing date - date of creation)
    Total cycle time (cycle time = closing date - date of creation)
    Number of reallocations (sum)


    DL - (deadline) formula is, closed date < = target_date

    This should be displayed, grouped by year, then month, then the assignment group. The values must be in descending order (dates) is not sure that group in operation here.
    I am able to write the code base of the foregoing, but group from the year, month, and group assignment is pretty confusing to me.


    Can someone give me a voucher code...

    This may not give you exactly what you want, but if all goes well, it will give you something to work with:

    WITH tickets AS (
      SELECT TO_CHAR(created, 'YYYY') created_year,
             TO_CHAR(created, 'MM') created_month,
             assignment_group,
             COUNT(sr_number) ticket_count,
             AVG(closed - created) avg_cycle_time,
             SUM(closed - created) tot_cycle_time,
             COUNT(reassignment_count) reassign_count
       FROM dummy
       GROUP BY TO_CHAR(created, 'YYYY'),
                TO_CHAR(created, 'MM'),
                assignment_group
    ),
    dl_tickets AS (
      SELECT TO_CHAR(created, 'YYYY') created_year,
             TO_CHAR(created, 'MM') created_month,
             assignment_group,
             COUNT(sr_number) ticket_in_dl_count
        FROM dummy
        WHERE closed <= target_date
        GROUP BY TO_CHAR(created, 'YYYY'),
              TO_CHAR(created, 'MM'),
              assignment_group
    )
    SELECT t.created_year,
           t.created_month,
           t.assignment_group,
           t.ticket_count,
           NVL(dl.ticket_in_dl_count, 0) ticket_in_dl_count,
           NVL(dl.ticket_in_dl_count/t.ticket_count, 0) * 100 pct_ticket_in_dl_count,
           t.avg_cycle_time,
           t.tot_cycle_time,
           t.reassign_count
      FROM tickets t,
           dl_tickets dl
      WHERE t.created_year = dl.created_year (+)
      AND t.created_month = dl.created_month (+)
      ORDER BY created_year DESC, created_month DESC
    

    Published by: user1983440 on May 27, 2013 15:47 - added reassign_count

    Published by: user1983440 on May 27, 2013 15:54 - added ORDER BY

  • FRM - 40212 / FRM - 40222 error on a radio during the query group

    Hi all

    This is my first post, so please bear with me if I did not provide enough information or am not clear at all.

    I use Forms Builder (Web) on a 10g database. I have a number of databases and elements non-base of data as part of a block of data.
    My problem is that when I enter a value in a field and click the query button, I have an invalid value FRM-40212 for error field on my radio group (section disabled, non-base of data, which is populated by programming in the triggers of post requests and amended list only). When I click ok, I get an error of FRM-40222 disabled point Validation failure on the same radio group.

    This does not happen if I click on the button "Enter the query" before you enter values in the fields, but I don't want my users to encounter this error if they try to interrogate without clicking "Enter the query" first.

    I would like to know why exactly this error happens - what it means?
    I read in other forums that setting the required article property to false solves this problem. But how can I do this with a group of radio buttons? And if it is not possible, anyone have any suggestions for other workaround solutions?

    Thanks in advance,

    Abigail

    Hello

    You can avoid this by defining "Mapping of other values" to a fo value of radio buttons. As if you need to radio radio1 and radio2 associated group R1 radio button, then set the option buttons the initial value of this property to 'Mapping of other values' radio button R1. You will not see this error.

    This error occurs because as your loading a screen without assigning a value to the option button.

    If this helps brand question as answer or useful.

    Thank you
    Pavan.

  • Helps the query in the effects control.

    Hello everyone, I hope that someone can help you.

    I have a little trouble trying to move images around the screen in my sequence to create an animation of a cursor moving to another location. The problem is when I put a marker in the query in the effect control to it's own journey sometimes going upward or down or left or right. I see that there are lines that are the focus of the image, as well as those of the tool pen in Photoshop and I think that that is what is causing the image of the cursor moving on its own. The two same lines by an image to make a smooth arch of movement these lines of travel to smooth the movement rather than a simple at the following location.

    I was wandering because this is the case whenever I put a new marker in the motion effects controls if there is something that is originally what I can disable. I can move these lines from the central point, but that does not make the smoother actions in my sequence.

    Any help is really appreciated.

    You set keyframes on linear:

    Adobe Premiere Pro help. Control to make changes using keyframe interpolation

  • Helps the query using summary on partition

    I don't know that miss me something small here. I need to make an inventory of end.
    The formula is the following:


    For the 501, end = store inventory
    -closing inventory 7292.19
    -supplies - 30,64 closing stock
    -closing inventory for buns - 1002.34
    = -----------
    6259.21
    I can get the stock of closing with analytics, but cannot end inventory.

    My dollar gap is also swollen. It should be 780.55 for store 501;

            
      CREATE TABLE "SUBQUERY_CATEGORIES" 
       (     "STOREID" NUMBER NOT NULL ENABLE, 
         "WEEK_NBR" NUMBER, 
         "DESCRIPTION" VARCHAR2(100 BYTE) NOT NULL ENABLE, 
         "OPEN_INVENTORY" NUMBER, 
         "CLOSING_INVENTORY" NUMBER, 
         "TRANSFER_IN_COST" NUMBER, 
         "TRANSFER_OUT_COST" NUMBER, 
         "DELV_COST" NUMBER, 
         "PREV_DELV_COST" NUMBER, 
         "TOTAL_COST" NUMBER, 
         "DOLLAR_VARIANCE" NUMBER
       ) ;
     
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Other Foods-I',880.04,837.16,17.32,0,491.92,880.044,837.158,35124.92);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Shortening-I',199.7,200.32,0,0,99.85,199.7,200.324,390.45);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Meat-I',154.69,464.06,168.75,42.188,1406.25,154.688,464.063,1239.85);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Bacon-I',74.99,62.63,19.405,0,154.16,74.992,62.628,1239.85);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Repairs & Maint',0,0,0,0,195,0,0,780.55);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Supplies',25.92,30.64,0,0,139.43,25.923,30.637,37466.58);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Drinks-I',585.06,750.36,0,0,715.87,585.058,750.358,8678.93);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Chili Ingridients-I',177.99,214.47,5.918,5.918,302.88,177.995,214.466,4683.32);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Meat-I',540,264.38,14.063,28.125,1181.25,540,264.375,780.89);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Paper-I',955.71,839.86,0,15.308,600.54,955.71,839.859,19131.9);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Supplies',11.78,9.43,0,0,158.85,11.783,9.427,17570.11);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Produce-I',180.5,98.64,0,0,206,180.498,98.638,3904.47);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Condiments-I',170.14,153.46,8.668,0,164.86,170.14,153.456,6819.16);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Repairs & Maint',0,0,0,0,500,0,0,390.45);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Fries-I',78.22,120.33,54.15,18.05,631.75,78.217,120.333,619.92);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Paper-I',1113.09,1093.63,50.884,14.07,846.22,1113.089,1093.633,43711.01);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Cheese-I',63.78,58.7,0,0,197.07,63.783,58.704,1171.34);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Produce-I',201.56,304.85,0,0,554.85,201.56,304.847,7805.54);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Buns-I',1064.44,793.73,0,0,191.36,1064.44,793.73,780.89);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Bacon-I',251.95,155.9,0,0,115.62,251.95,155.902,780.89);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Paper-I',806.87,871.74,12.113,8.448,674.56,806.871,871.741,30376.25);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Chicken-I',561.16,570.93,94.457,0,1568.81,561.156,570.929,5463.88);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Chicken-I',285.86,534.67,73.007,35.97,1402.86,285.858,534.67,4339.46);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Drinks-I',1061.6,1040.97,0,0,584.59,1061.597,1040.971,5466.26);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Breakfast-I',437.9,376.44,0,0,272.42,437.904,376.438,12488.86);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Condiments-I',173.67,159.72,0,3.251,187.55,173.671,159.721,4294.92);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Chili Ingridients-I',93.59,149.49,2.445,0,253.85,93.594,149.489,3719.54);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Buns-I',873.54,914.48,0,0,441.6,873.54,914.48,1239.85);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Fries-I',39.11,126.35,36.1,36.1,884.45,39.108,126.35,780.55);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Supplies',4.71,4.71,0,0,195.53,4.713,4.713,27896.56);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Other Foods-I',615.63,627.42,1.701,0,374.4,615.63,627.419,26656.71);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Chicken-I',702.5,471.66,0,65.64,1120.39,702.502,471.664,2733.13);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Dairy-I',176.9,128.3,0,0,332.14,176.904,128.304,5463.88);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Dairy-I',171.78,85.3,0,0,109.38,171.783,85.297,2342.68);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Dairy-I',122.71,89.86,0,0,288.98,122.706,89.856,3719.54);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Cheese-I',140.03,109.46,0,0,131.38,140.028,109.461,1859.77);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Produce-I',151.15,169.85,0,3.44,270.85,151.148,169.852,6199.23);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Shortening-I',249.63,259.61,0,0,259.61,249.625,259.61,780.55);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Bacon-I',116.58,115.62,0,0,308.32,116.581,115.62,1561.11);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Repairs & Maint',0,0,0,0,200,0,0,619.92);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Cheese-I',130.9,174.52,0,0,328.45,130.897,174.516,2341.66);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Condiments-I',225.65,207.39,0,0,247.81,225.645,207.394,8586.09);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Chili Ingridients-I',159.45,109.79,5.918,0,159.6,159.45,109.788,2342.68);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Meat-I',752.34,696.09,0,28.125,1800,752.344,696.094,1561.11);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Buns-I',1090.2,1002.34,0,0,524.4,1090.2,1002.34,1561.11);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Fries-I',147.41,88.75,0,0,595.65,147.408,88.746,390.45);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (27,1,'Other Foods-I',658.37,645.92,0,1.701,373.34,658.375,645.925,16789.22);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (501,1,'Drinks-I',1290.03,1153.85,0,0,689.84,1290.032,1153.848,12488.86);
    Insert into SUBQUERY_CATEGORIES (STOREID,WEEK_NBR,DESCRIPTION,OPEN_INVENTORY,CLOSING_INVENTORY,TRANSFER_IN_COST,TRANSFER_OUT_COST,DELV_COST,PREV_DELV_COST,TOTAL_COST,DOLLAR_VARIANCE) values (25,1,'Shortening-I',159.76,179.73,0,0,199.7,159.76,179.73,619.92);
    
    SET DEFINE OFF 
    
    with categorycosts as 
     ( 
             SELECT             storeid 
                                 ,  week_nbr
                                 ,  UPPER(TRIM(description))  description                
                                 ,  NVL(prev_delv_cost + transfer_in_cost + delv_cost - transfer_out_cost - total_cost, 0) AS  cost 
                                 ,  open_inventory 
                                 ,  dollar_variance                         
                                 ,  sum(closing_inventory ) over (partition by storeid, week_nbr )  closing_inventory                   
                           --    ,  closing_inventory
                              from  subquery_categories
                              where storeid = 501
     )
      ,  pivoted_cat_costs AS
     (SELECT  storeid
                 , week_nbr
                , MAX(DECODE(closing_inventory, 0, 0, closing_inventory))  -  NVL(MAX(DECODE(UPPER(TRIM(description)), 'SUPPLIES', cost)), 0)  -       NVL(MAX(DECODE(UPPER(TRIM(description)), 'BUNS-I', cost)), 0)      as   closing_inventory
                , MAX(DECODE(dollar_variance, 0, 0, dollar_variance))                as   dollar_variance
               ,    NVL(MAX(DECODE(UPPER(TRIM(description)), 'SUPPLIES', cost)), 0)                 supplies
               ,    NVL(MAX(DECODE(UPPER(TRIM(description)), 'REPAIRS & MAINT', cost)), 0)                     repairs_and_maint        
               ,    NVL(MAX(DECODE(UPPER(TRIM(description)), 'BUNS-I', cost)), 0)             as buns            
          FROM   categorycosts
          GROUP BY storeid,  week_nbr
     )
    select * from pivoted_cat_costs;
    -= = So I separated it and still get incorrect result
          SELECT                   storeid   
                                 ,  week_nbr
                                 ,  UPPER(TRIM(description))  description                
                                 ,  NVL(prev_delv_cost + transfer_in_cost + delv_cost - transfer_out_cost - total_cost, 0) AS  cost 
                                 ,     open_inventory 
                                 ,    dollar_variance                         
                             --  ,   sum(closing_inventory ) over (partition by storeid, week_nbr )  closing_inventory                   
                                 ,             closing_inventory
                              from  subquery_categories;
     
    The results should be:
     store 501                   ending inventory  =  6259.21            buns s/b   1002.34                inv variance 780.55
     Store 27                    ending inventory  =  4220                 buns s/b = 793.73                inv variance 390.45 
     Store 25                    ending inventory  =  4283                 buns       914.48                  inv variance 619.92
    There is an anomaly out Bill so it can produce the vairiance of good quality, but inv variance that my request is back is swollen.
    Can someone tell me what I am doing wrong?

    Published by: TheHTMLDJ on December 9, 2009 06:42
    SET DEFINE OFF has added and removed the subquery_categories schema name

    Well, I asked for the logic as the specification and not necessarily a query. :)
    Here's the query that gets your inventory of desired end.

    with categorycosts as
     (
             SELECT             storeid
                                 ,  week_nbr
                                 ,  UPPER(TRIM(description))  description
                                 ,  NVL(prev_delv_cost + transfer_in_cost + delv_cost - transfer_out_cost - total_cost, 0) AS  cost
                                 ,  open_inventory
                                 ,  dollar_variance
                                 ,  sum(closing_inventory ) over (partition by storeid, week_nbr )  closing_inventory
                                 ,  DECODE(UPPER(TRIM(description)), 'SUPPLIES', closing_inventory) supp_cls_inv
                                 ,  DECODE(UPPER(TRIM(description)), 'BUNS-I', closing_inventory) bun_cls_inv
                              from  subquery_categories
                              where storeid = 501
     )
      ,  pivoted_cat_costs AS
     (SELECT  storeid
                 , week_nbr
                , MAX(DECODE(closing_inventory, 0, 0, closing_inventory))  -  NVL(MAX(supp_cls_inv), 0)  -       NVL(MAX(bun_cls_inv), 0)      as   closing_inventory
                , MAX(DECODE(dollar_variance, 0, 0, dollar_variance))                as   dollar_variance
               ,    NVL(MAX(DECODE(UPPER(TRIM(description)), 'SUPPLIES', cost)), 0)                 supplies
               ,    NVL(MAX(DECODE(UPPER(TRIM(description)), 'REPAIRS & MAINT', cost)), 0)                     repairs_and_maint
               ,    NVL(MAX(DECODE(UPPER(TRIM(description)), 'BUNS-I', cost)), 0)             as buns
          FROM   categorycosts
          GROUP BY storeid,  week_nbr
     )
    select * from pivoted_cat_costs;
    

    I still don't know the logic (or specifications) to derive your dollor expected variance.

  • Help with the query GROUP BY?

    Why the habit of this work? When I run the code with the first where clause it works fine.
    select diffrating, count (diffrating) 
    from IT220_HOLIDAYDETAILS
    where diffrating = 'A'
    GROUP BY diffrating
    It returns the result that there is a diffirating marked "A".

    However, when I try to add other clauses he says "no data found"?
    select diffrating, count (diffrating) 
    from IT220_HOLIDAYDETAILS
    where diffrating = 'A'
    and diffrating = 'B'
    and diffrating = 'C'
    and diffrating = 'D'
    and diffrating = 'E'
    GROUP BY diffrating
    How can this be when he came 'A' data in the first place? Surely, it should return 'A' as a negative because it worked before?

    What I want is to count all results for each diffrating and return them. Any reason, why it does not work?

    Thanks in advance!

    It returns nothing because you try to select a diffrating whose value has, b, c, d and e at the same time.

    select diffrating, count (diffrating)
    from IT220_HOLIDAYDETAILS
    GROUP BY diffrating
    

    is not already display what you want?

  • Helps the query using LESS

    Hello Experts

    I can't in select the record_sequence in the output. Please see the part of the desired effect.
    Please help solve this problem.

    Is the version of Oracle, I'm working on that

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options

    Thank you

    RB

    TABLE1 AS
    (
    SELECT '28' EXAM_CD1, EXAM_CD2 '29', '10' EXAM_CD3, 111' CAND_ID FROM DUAL UNION ALL
    SELECT '21' EXAM_CD1, EXAM_CD2 '39', '20' EXAM_CD3, 112' CAND_ID FROM DUAL UNION ALL
    SELECT '22' EXAM_CD1, EXAM_CD2 '49', '30' EXAM_CD3, 113' CAND_ID FROM DUAL UNION ALL
    SELECT 'EXAM_CD1 23', '59' EXAM_CD2, EXAM_CD3 ' 40', 114' CAND_ID FROM DUAL UNION ALL
    SELECT '24' EXAM_CD1, EXAM_CD2 '69', '50' EXAM_CD3, 115' DOUBLE CAND_ID)
    AS TABLE2
    (
    SELECT EXAM_CD '28', '111' CANDID, 1 RECORD_SEQ OF DOUBLE UNION ALL
    SELECT '30' EXAM_CD, '113' CANDID, 2 RECORD_SEQ FROM DUAL UNION ALL
    SELECT EXAM_CD '94', '111' CANDID, 3 RECORD_SEQ OF DOUBLE UNION ALL
    SELECT EXAM_CD '69', '115' CANDID, 4 DOUBLE RECORD_SEQ)
    (
    SELECT EXAM_CD FROM TABLE2, CANDID
    LESS
    SELECT CAND_ID,
    MAX (L CASE WHEN 1 EXAM_CD1 THEN WHEN 2 THEN of OTHER EXAM_CD2 EXAM_CD3 END) exam_code
    FROM TABLE1,
    (SELECT LEVEL L FROM DUAL CONNECT BY LEVEL < = 3)
    CAND_ID GROUP, L)

    The aim is

    CAND_ID, EXAM_CD, RECORD_SEQ
    * 111, 94, 3 *.

    Hello

    Rb2000rb65 wrote:
    The solution use not less as long as I get my results using the latest features, it is good with me.

    Good idea!
    UNMIS is not the best tool for this task. The saved query gets the exam_cd and the Candide you want, but you can't find the record_seq because there of nothing like record_seq in table1.

    You can do this way:

    SELECT     *
    FROM     table2     m
    WHERE     NOT EXISTS (
                        SELECT  1
                    FROM    table1
                    WHERE   m.candid      = candid
                    AND     m.exam_cd  IN ( exam_cd1
                                             , exam_cd2
                                 , exam_cd3
                                 )
                 )
    ;
    

    I guess you could use LESS, like this

    SELECT     *
    FROM     table2
    WHERE     (exam_cd, candid)
         IN (
                SELECT  ...  -- The MINUS query you posted goes here
            )
    ;
    

    but it is unecessarily complicated.

  • using the query - group

    Hi all
    I need to get the sum (sal) and the sum (comm) using the select query...
    I use a group of... but could not get the result...
    For example... If the table is
    ENO ename sal comm deptno job
    1234 2000 1 10 Chief john
    1235 1000 2 20 andrew seller
    1236 2000 3 20 steven Manager
    Clerk robert 1237 600 4 10
    Manager of laura 1238 2000 5 20
    1239 500 6 30 dan seller
    1240 500 7 10 james clerk

    I need display all the columns in the select query and the result should be as follows:
    ENO ename sal comm deptno sum (sal) sum (comm) employment
    1234 2000 1 10 6000 9 Chief john
    1235 1000 2 20 1500 8 andrew seller
    1236 2000 3 20 6000 9 steven Manager
    Clerk robert 1237 600 4 10 1100 11
    1238 2000 5 20 6000 9 laura Manager
    1239 500 6 30 1500 8 dan seller
    1240 500 7 10 1100 11 james clerk

    I appreciate your help... Thank you!

    Use anaytic SUM:

    SQL> select  empno,
      2          ename,
      3          job,
      4          sal,
      5          comm,
      6          deptno,
      7          sum(sal) over(partition by deptno) sum_sal,
      8          sum(comm) over(partition by deptno) sum_comm
      9    from  emp
     10  /
    
         EMPNO ENAME      JOB              SAL       COMM     DEPTNO    SUM_SAL   SUM_COMM
    ---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
          7782 CLARK      MANAGER         2450                    10       8750
          7839 KING       PRESIDENT       5000                    10       8750
          7934 MILLER     CLERK           1300                    10       8750
          7566 JONES      MANAGER         2975                    20      10875
          7902 FORD       ANALYST         3000                    20      10875
          7876 ADAMS      CLERK           1100                    20      10875
          7369 SMITH      CLERK            800                    20      10875
          7788 SCOTT      ANALYST         3000                    20      10875
          7521 WARD       SALESMAN        1250        500         30       9400       2200
          7844 TURNER     SALESMAN        1500          0         30       9400       2200
          7499 ALLEN      SALESMAN        1600        300         30       9400       2200
    
         EMPNO ENAME      JOB              SAL       COMM     DEPTNO    SUM_SAL   SUM_COMM
    ---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
          7900 JAMES      CLERK            950                    30       9400       2200
          7698 BLAKE      MANAGER         2850                    30       9400       2200
          7654 MARTIN     SALESMAN        1250       1400         30       9400       2200
    
    14 rows selected.
    
    SQL> 
    

    SY.

  • Helps the query using case and County

    Hello!

    I have problems with a small part of a query below that finally can settle the invoice price.

    (count (distinct spm97.sample_id) * 36.1) as "PROFILE."
    case count (distinct spm33.sample_id)
    When (count (distinct spm97.sample_id) = 0) then (count (distinct spm33.sample_id) * 26)
    another (count (distinct spm33.sample_id) * 4.75)
    put an end to 'CC ',.

    The first line works - 0 or 36.10 is returned depending on whether or not a profile has been ordered for the sample.

    The cost of CC is 4.75 if a profile was also sentenced, if it isn't then the cost is 26. The case statement is supposed to verify this and return the exact amount, but I can't make it work... I get the error message that a closing parenthesis is missing somewhere in the middle of line 3, if that helps.

    Any advice would be much appreciated! Of course, this isn't the entire query - joins and all are all working well, it's just this little section with the County that I can't just.

    Thank you

    JO

    the piece of code below, seems to me is incorrect

        CASE COUNT(DISTINCT spm33.sample_id)
            WHEN
                (
                    COUNT(DISTINCT spm97.sample_id) = 0
                )
            THEN (COUNT(DISTINCT spm33.sample_id) * 26)
            ELSE (COUNT(DISTINCT spm33.sample_id) * 4.75)
        END AS "CC"
    

    It seems that the requirement here is that if * 'COUNT (DISTINCT spm97.sample_id) = 0' *, then * "CC" * should be ' COUNT (DISTINCT spm33.sample_id) (* 26) "ELSE, it should be" COUNT (DISTINCT spm33.sample_id) (* 4.75)»
    If this is the case, the statement must include:

        CASE COUNT(DISTINCT spm97.sample_id)
            WHEN
                0
            THEN (COUNT(DISTINCT spm33.sample_id) * 26)
            ELSE (COUNT(DISTINCT spm33.sample_id) * 4.75)
        END AS "CC"
    
  • PROBLEM IN THE QUERY GROUP

    Hi all
    MY PAINTINGS ARE

    1 PRTRINCE AREAS ARE: SHOP, TIMESAVED, TIMETAKEN, EMPNO
    2 PRMAINCM: UNIT, STDHOURS

    NOW, I WANT TO DO THE NEXT THING

    I WANT TO CALCULATE THE % FOR EACH SHOW DEPENDING ON STORE AND SHOP

    I mean

    SELECT A.SHOP, SUM (A.TIMETAKEN), SUM (A.TIMESAVED)
    , SUM (A.TIMESAVED) * 100/COUNT (A.EMPNO) * B.STDHOURS OF
    PRTRINCE A, PRMAINCM B WHERE
    A.SHOP = B.UNIT
    A.SHOP GROUP

    BUT IT DOES NOT WORK AS IT IS SAID TO COUNT (A.EMPNO) * B.STDHOURS NO NOT A GROUP BY EXPRESSION

    SUGGEST A QUERY THAT CAN SOLVE MY PROBLEM

    CONCERNING
    AERTS.

    Hi AEK.
    Include B.STDHOURS in your group by clause and check.

    SELECT A.SHOP,
           SUM(A.TIMETAKEN),
           SUM(A.TIMESAVED),
           SUM(A.TIMESAVED)*100/COUNT(A.EMPNO) * B.STDHOURS
    FROM PRTRINCE A, PRMAINCM B
    WHERE A.SHOP=B.UNIT
    GROUP BY A.SHOP, B.STDHOURS
    

    Tip: use media suitable in your script according to your requirement:

    select 5 * 100 / 10 * 4 from dual
    =>200
    
    select 5 * 100 / (10 * 4) from dual
    =>12.5
    

    Slight changes in the script: included claim to count (empno)

    with PRTRINCE as (
    select 'A' as SHOP, 10 as TIMESAVED, 50 as TIMETAKEN, 1 as EMPNO from dual union all
    select 'A' as SHOP, 15 as TIMESAVED, 45 as TIMETAKEN, 2 as EMPNO from dual union all
    select 'A' as SHOP, 5 as TIMESAVED, 60 as TIMETAKEN, 2 as EMPNO from dual union all
    select 'A' as SHOP, 15 as TIMESAVED, 45 as TIMETAKEN, 2 as EMPNO from dual union all
    select 'B' as SHOP, 12 as TIMESAVED, 48 as TIMETAKEN, 3 as EMPNO from dual
    ),
    PRMAINCM as
    (
    select 'A' as UNIT, '8' as STDHOURS from dual union
    select 'B' as UNIT, '10' as STDHOURS from dual
    )
    SELECT A.SHOP,
           SUM(A.TIMETAKEN) TIMETAKEN,
           SUM(A.TIMESAVED) TIMESAVED,
           (SUM(A.TIMESAVED)*100/COUNT(distinct A.EMPNO) * B.STDHOURS) XYZ
    FROM PRTRINCE A, PRMAINCM B
    WHERE A.SHOP=B.UNIT
    GROUP BY A.SHOP, B.STDHOURS
    
    SHOP     TIMETAKEN     TIMESAVED     XYZ
    A     200     45     18000
    B     48     12     12000
    

    Concerning
    Imran

    Published by: Imran Alcantara on April 13, 2010 10:35; updated the script with sample data

  • Join itself find missing links, helps the query, table

    Data in the table:
    tblRelationships
    RelationshipID    SourceID   DestinationID
    1                      100          200
    2                      200          100
    3                      300          100
    I'm trying to right a query that returns the relationships that are the only way.

    So for the above data, 3 would return because he'll only source 300 to 100 and not source from 100 to 300.

    Published by: avalanche333 on January 15, 2010 12:26
    SQL> create table tblRelationships (
      2  RelationshipID       NUMBER,
      3  SourceID     NUMBER,
      4  DestinationID NUMBER)
      5  /
    
    Table created.
    
    SQL> insert into tblRelationships values (1,100,200);
    
    1 row created.
    
    SQL> insert into tblRelationships values (2,200,100);
    
    1 row created.
    
    SQL> insert into tblRelationships values (3,300,100);
    
    1 row created.
    
    SQL>
    SQL> select relationshipid from tblrelationships
      2  where sourceid in (
      3  select SourceID from tblRelationships
      4  minus
      5  select destinationid from tblRelationships)
      6  /
    
    RELATIONSHIPID
    --------------
              3
    
    SQL> drop table tblRelationships
      2  /
    
    Table dropped.
    
    SQL> 
    
  • Helps the query Condition

    -Create/insert example:

    create table xxdummy)
    integer ID,
    name varchar2 (40),
    Description varchar2 (100)
    );

    insert into xxdummy values (1, 'L', ' press L Simple');
    insert into xxdummy values (2, 'XL', "XL with no film");
    insert into xxdummy values (2, 'web', "XL with no film");
    insert into xxdummy values (3, 'XL', 'XL with the Film');
    insert into xxdummy values (3, 'Film', 'XL with the Film');
    insert into xxdummy values (3, 'print', 'XL with the Film');
    insert into xxdummy values (4, the of ', 'servo with the film');
    insert into xxdummy values (4, 'Film', 'servo with the film');
    insert into xxdummy values (5, the servo only ',' ');
    insert into xxdummy values (6, 'L', 'Press L Simple');
    insert into xxdummy values (7, 'XL', "XL with no film");
    insert into xxdummy values (8, 'XL', 'XL with the Film');
    insert into xxdummy values (8, 'Film', 'XL with the Film');
    insert into xxdummy values (8, 'guide', 'XL with the Film');

    -drop table xxdummy;

    Select * from xxdummy;

    SELECT id, description, decode type ("name, ' the, 'L only', 'XL', ' Got XLs here","no opinion")
    of xxdummy
    WHERE name in ('l', 'XL')

    In above query for the type of column, I want to display 'Only L', "XL with Film", "XL without Film.

    How can I do this?
    Thank you

    Hello

    You can change the Andreas solution' to show the name instead of the description and some minor changes in the wording of the type.
    You can also rearrange the expression BOX so that you do not need a nested case.

    select id,
           name,
           CASE  WHEN name = 'L' THEN
             ' L Only'
           WHEN  name != 'XL' THEN
             'dont know'
           WHEN INSTR (description, 'with no') >0 THEN
               'XL No Film'
           ELSE
               'XL Film'
           END type
    from    xxdummy
    where      name in ('L','XL' )
    ;
    
  • Helps the query!

    Question: Program to write PLSQL to calculate electricity charge for given units and for the pending amount includes 5%.

    Entry: Number of units and amount pending

    output: total amount to pay.

    slab:

    min_units Max_units Rate
    01993
    2002995
    3003997
    > 4009

    PROGRAM:

    DECLARE

    v_unit: = number (7): & Enter_consumed_units;

    v_total_amount number (7.2);

    v_pending_amount number (5): = & Enter_pending_amount;

    BEGIN

    v_total_amount: = BOX

    WHEN v_unit < 199 THEN v_unit * 3 + v_pending_amount;

    WHEN v_unit BETWEEN 200 AND 299 CAN (v_unit-199) * 199 * 5 + 3 + (v_pending_amount * 0.05);

    WHEN BETWEEN 300 AND 399 v_unit THEN (v_unit-299) * 7 + (100 * 5) + 199 * 3 + (v_pending_amount * 0.05);

    WHEN v_unit > 400 THEN (v_unit-399) * 9 +(100*5) + 199 * 3 +(100*7) + (v_pending_amount * 0.05);

    END;

    dbms_output.put_line (' Total amount to ' | v_unit |) "consumed". "is ' |" v_total_amount);

    END;

    /

    But the above program gives me error, the following error "Bind Variable 199 not found" when I get 199 as a unit.

    Hello

    v_unit: = number (7): & Enter_consumed_units;

    should be

    v_unit number (7): = & Enter_consumed_units;

    Do not write code so both.  Take baby steps.  Write as little as possible (in this case, maybe 3 lines), test, repair (if necessary), test again and only when as long as it works, add another 1 or 2 lines.  When you get errors, you will have a better idea of exactly what caused the error. It will usually be in the bit of code added to the final stage of baby.

    Furthermore, you need not PL/SQL to get these results.  This looks like a school exercise, but you still haven't PL/SQL.

  • Help the query to list all the days between MIN and MAX date in a table

    Hello

    Sorry, this may have already responded earlier, but I really struggled to find a previous response with the new provision of the RTO.

    In a DB 11 g, I date MIN and MAX in a table:

    {code}

    SELECT MIN (process_date) start_date, MAX (process_date) end_date FROM my_table;

    {code}

    I would get every day between these 2 dates. I mean even is there is no record in the table for a date.

    Is this possible?

    Thanks in advance,

    Olivier

    Hello

    Do you mean something like this?

    ranit@XE11GR2>> ed
    Wrote file c:\rb\1.sql
    
      1  with xx as
      2  (
      3      select
      4     to_date('05-06-2013','dd-mm-yyyy') min_d,
      5     to_date('20-06-2013','dd-mm-yyyy') max_d
      6      from dual
      7  )
      8  --
      9  -- end of test data
     10  --
     11  select
     12     min_d + level date_x
     13  from xx
     14* connect by level<=(max_d-min_d)
    ranit@XE11GR2>> /
    
    DATE_X
    -------------------
    06-06-2013 00:00:00
    07-06-2013 00:00:00
    08-06-2013 00:00:00
    09-06-2013 00:00:00
    10-06-2013 00:00:00
    11-06-2013 00:00:00
    12-06-2013 00:00:00
    13-06-2013 00:00:00
    14-06-2013 00:00:00
    15-06-2013 00:00:00
    16-06-2013 00:00:00
    17-06-2013 00:00:00
    18-06-2013 00:00:00
    19-06-2013 00:00:00
    20-06-2013 00:00:00
    
    15 rows selected.
    
  • helps the query again

    Hi all
    I have a table as shown below:
    NO NAME SAL
    ---------- ---------- ----------
    1 x 200
    1 to 100
    2 y 400
    2 b 300
    I want to ask in such a way that the result should be as follows:
    NO NAME SAL
    ---------- ---------- ----------
    1
    x 200
    a 100
    2
    y 400
    b 300
    How to write this... Thanks iin advance...

Maybe you are looking for