helps the load by clause of the query.

guys I have a table like this
 create table fgbtrnh ( fgbtrnh_doc_code varchar2(9),
                                         fgbtrnh_trans_date date,
                                         fgbtrnh_trans_amt number(17,2),
                                         fgbtrnh_acct varchar2(6) ,
                                         fgbtrnh_fund_code varchar2(6),
                                         fgbtrnh_rucl_code varchar2(6) );
 
with data like this.
   insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('J0005445','31-MAY-10','38491','6001','BD01','360098');
 insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('L0000005','01-JUL-08','38260','6001','BD01','360098');
 insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('L0000002','30-JUN-08','24425.29','6001','BD01','360125');
 insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('L0000002','30-JUN-08','48057.71','6001','BD01','360125');
 insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('M0000002','30-JUN-08','90','7200','BD01','360098');
I would like to get a total run of these elements, so I tried something like that.
select  f.fgbtrnh_doc_code,f.fgbtrnh_trans_date,f.fgbtrnh_trans_amt, sum(f.fgbtrnh_trans_amt)
over
(--partition by  f.fgbtrnh_doc_code
order by fgbtrnh_trans_date desc  ROWS UNBOUNDED PRECEDING 
--group by  f.fgbtrnh_doc_code
)total
From fgbtrnh f 
where f.fgbtrnh_fund_code in ('360098', '360125')
and f.fgbtrnh_rucl_code = 'BD01'
and f.fgbtrnh_acct = '6001'
order by  f.fgbtrnh_trans_date desc,  f.fgbtrnh_doc_code
but I find myself with a result set as


'FGBTRNH_DOC_CODE', 'FGBTRNH_TRANS_DATE', 'FGBTRNH_TRANS_AMT', 'TOTAL '.
"J0005445", MAY 31, 10, 38491, 38491
"L0000005", 1 JULY 08, 38260, 76751
"L0000002", 30 JUNE 08, 24425.29, 101176.29
"L0000002", 30 JUNE 08, 48057.71, 149234




I want to thave the cumulative total to start at the bottom in the other Word is my total column I would like to finish with the top 149234
so it should look something like this.





'FGBTRNH_DOC_CODE', 'FGBTRNH_TRANS_DATE', 'FGBTRNH_TRANS_AMT', 'TOTAL '.
"J0005445", MAY 31, 10, 38491, 149234
"L0000005", 1 JULY 08, 38260, 110743
"L0000002", 30 JUNE 08, 24425.29, 72483
"L0000002", 30 JUNE 08, 48057.71, 48057.71


I've tried everything and can't seem to make this work can someone please point me in the right direction.
I would really appreciate the help.
Thank you
Miguel

Hi, Miguel.

mlov83 wrote:
... Also, if you order only the lines, you won't need the windowing clause ("UNBOUNDED PRECEDING LINES"); the default value ("RANGE UNBOUNDED PRECEDING") will have exactly what you want, so you n;' no need to say it.

I don't really understand what you mean by that? But if I take a quick glance you say that all my lines will have to be unique, and then I won't have to use ("UNBOUNDED PRECEDING LINES")

I think you have guessed it right.
The ORDER BY clause Analytics don't have to result in a single ranking. There are good reasons for having a single oprdering, and there are good reasons for not having a single collation.
I mean that If the analytical ORDER BY is unique, then you need not to give a widnowing clause, such as the "LINES OF UNBOUNDED'.

Frank sorry if im asking some really stupid questions, but I have tried and tried to read and understand "partion by" and "over" works, but I'm not quite sure I understand yet.

It's not stupid at all! Analytical functions can be very subtle and confusing.

We will use a query based on the table scott.emp, which includes lines for each seveal deptno.

-- Tell SQL*Plus to put a blank line between deptnos, just to make the output easier to read
BREAK     ON deptno   SKIP 1     DUPLICATES

SELECT       deptno
,       ename
,       sal
,       SUM (sal) OVER ( PARTITION BY  deptno
                            ORDER BY        sal
                  ROWS            UNBOUNDED PRECEDING
                )     AS running_total
FROM       scott.emp
ORDER BY  deptno
,            sal          DESC
,       ename
;

Output:

`   DEPTNO ENAME             SAL RUNNING_TOTAL
---------- ---------- ---------- -------------
        10 KING             5000          8750
        10 CLARK            2450          3750
        10 MILLER           1300          1300

        20 FORD             3000         10875
        20 SCOTT            3000          7875
        20 JONES            2975          4875
        20 ADAMS            1100          1900
        20 SMITH             800           800

        30 BLAKE            2850          9400
        30 ALLEN            1600          6550
        30 TURNER           1500          4950
        30 MARTIN           1250          2200
        30 WARD             1250          3450
        30 JAMES             950           950

PARTITION BY deptno"means to do a separate calculation for each distinct value of deptno. Lines with deptno = 10 effect the outcome on the lines where deptno = 20 or deptno = 30. Since there are 3 distinct values of deptno, there are 3 separate running totals.

Note that the analytical ORDER BY clause translates into only a partial ranking. If there are two or more lines in the same deptno who have the same sal, look what can happen:
{code}
"DEPTNO ENAME SAL RUNNING_TOTAL.
---------- ---------- ---------- -------------
... 30 1500 4950 TURNER
30 MARTIN 1250 2200
1250 3450 DISTRICT 30
30 JAMES 950 950
{code}
MARTIN and WARD are in the same partition (deptno = 30), and they both have the same sal (1250), so there is no reason why one of these lines would be considered 'before' it. When you use a windowing clause based on the LINES, as stated above, and there is equality for which line comes first (as there is equality between MARTIN and WARD), then one of the lines will arbitrarily be condidered before this one. In this example, it happened to chose MARTIN as the 2nd lowest sal, so running_total = 2200 (= 950 + 1250) on the line for MARTIN and running_total = 3450 (950 + 1250 + 1250) on the WARD line. There is no particular reason for this; It is completely arbitrary. I could do exactly the same question tomorrow or in 10 minutes and get running_total = 2200 to the rank of WARD and 3450 on MARTIN.
However, it is no coincidence that MARTIN comes before WARD at the exit. the * request * ORDER BY clause (which has nothing to do with the analytical ORDER BY clause) ensures that, when two lines have the same deptno and sal, then the one with the earlier ename will come first.

Now, what is the difference between a window based on the LINES and a window on the BEACH bnased?
One difference is that, when a link appears in the ORDER BY clause, all rows with the same value of sal get the same value for SUM (sal):
{code}
SELECT DeptNo
ename
sal
SUM (sal) over (PARTITION BY deptno
ORDER BY sal
) AS running_total
FROM scott.emp
ORDER BY deptno
sal DESC
ename
;
{code}
Note that the only difference between the first query above, and this one is that it does not have an analytical windowing clause, then the default window, * RANGE * UNBOUNDED PRECEDING is used.
Output:
{code}
"DEPTNO ENAME SAL RUNNING_TOTAL.
---------- ---------- ---------- -------------
10 5000 8750 KING
10 2450 3750 CLARK
10 1300 1300 MILLER

20 FORD 3000 10875
20 3000 10875 SCOTT
20 JONES 2975 4875
20 1100 1900 ADAMS
20 SMITH 800 800

30 2850 9400 BLAKE
30 1600 6550 ALLEN
30 1500 4950 TURNER
30 MARTIN 1250 3450
1250 3450 DISTRICT 30
30 JAMES 950 950
{code}
Again, look MARTIN and WARD near the end. They have both the sal of the soul, so they both have the same running_total = 3450 (= 950 + 1250 + 1250). This is often a desirable outcome, but in your case, it seems not to be. If you want running_totals MARTIN and WARD, then recesses you must use a window LINE, as we have done previously, or add a breakage in the ORDER BY clause, like this:
{code}
SELECT DeptNo
ename
sal
SUM (sal) over (PARTITION BY deptno
ORDER BY sal
, ename DESC - changed (this is the only change)
) AS running_total
FROM scott.emp
ORDER BY deptno
sal DESC
ename
;
{code}
Output:
{code}
"DEPTNO ENAME SAL RUNNING_TOTAL.
---------- ---------- ---------- -------------
10 5000 8750 KING
10 2450 3750 CLARK
10 1300 1300 MILLER

20 FORD 3000 10875
20 3000 7875 SCOTT
20 JONES 2975 4875
20 1100 1900 ADAMS
20 SMITH 800 800

30 2850 9400 BLAKE
30 1600 6550 ALLEN
30 1500 4950 TURNER
30 MARTIN 1250 3450
1250 2200 DISTRICT 30
30 JAMES 950 950
{code}

Tags: Database

Similar Questions

  • 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 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>
    
  • 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.

  • 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"
    
  • 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...
  • Need help to load MySQL results in a query

    Hello, I need help to find out why my component of the tree is not being filled with the results of MySQL.

    I have a table of categories:
    ParentID - CategoryID - name

    Each top-level category has a ParentID of 0 (zero). I use php and a recursive function to build an array of results nested, then returning these results to Flex, making these results, a new collection of ArrayCollection, then assign that to the dataProvider of the tree.

    Result: my tree component is empty

    Suspicion: there must be a way with how my table is formed in PHP. If I play with how forms can I get strange results in the tree, so I know that's not a problem with the data passed to Flex.

    I enclose the PHP code used to form table and the output of the table being created

    Hi, thanks for the response. I discovered what the problem was. Table indexes should start with 0 instead of 1. I don't know why that is, but that solved my problem.

  • Need help in the optimization of the query with the Group and joins by clause

    I'm having the problem by running the following query... It takes a lot of time. To simplify, I added the two tables FILE_STATUS = stores the file load details and COMM table Board table job showing records treated successfully and which was communicated to the other system real. Records with status = T is trasnmitted to another system and traansactions with P is waiting.
    CREATE TABLE FILE_STATUS
    (FILE_ID VARCHAR2(14),
    FILE_NAME VARCHAR2(20),
    CARR_CD VARCHAR2(5),
    TOT_REC NUMBER,
    TOT_SUCC NUMBER);
    
    CREATE TABLE COMM
    (SRC_FILE_ID VARCHAR2(14),
    REC_ID NUMBER,
    STATUS CHAR(1));
    
    INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
    INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
    
    INSERT INTO COMM VALUES ('12345678', 1, 'T');
    INSERT INTO COMM VALUES ('12345678', 3, 'T');
    INSERT INTO COMM VALUES ('12345678', 4, 'P');
    INSERT INTO COMM VALUES ('12345678', 5, 'P');
    COMMIT;
    Here's the query I wrote to give me the details of the file that has been loaded into the system. He reads the table of State and the commission files to display the name of the file, total records loaded, total at the table of the commission and the number of records which has finally been passed successfully loaded (Status = T) with other systems.
    SELECT 
        FS.CARR_CD 
        ,FS.FILE_NAME 
        ,FS.FILE_ID
        ,FS.TOT_REC
        ,FS.TOT_SUCC
        ,NVL(C.TOT_TRANS, 0) TOT_TRANS
    FROM FILE_STATUS FS
    LEFT JOIN
    (
        SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
        FROM COMM
        WHERE STATUS = 'T'
        GROUP BY SRC_FILE_ID
    ) C ON C.SRC_FILE_ID = FS.FILE_ID
    WHERE FILE_ID = '12345678';
    In production, this request has several joins and takes a long time to deal with... the main culprit for me is the join on the COMM table to count the number of number of transactions sent. Please can you give me tips to optimize this query to get results faster? What I need to delete the Group and use the partition or something else. Help, please!

    Don't know if it will be faster based on the information provided, but analytical functions offer an alternative approach;

    select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
      from (select fs.carr_cd,
                   fs.file_name,
                   fs.file_id,
                   fs.tot_rec,
                   fs.tot_succ,
                   count(case
                            when c.status = 'T' then
                             1
                            else
                             null
                          end) over(partition by c.src_file_id) tot_trans,
                   row_number() over(partition by c.src_file_id order by null) rn
              from file_status fs
              left join comm c
                on c.src_file_id = fs.file_id
             where file_id = '12345678')
     where rn = 1;
    
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS
    ------- -------------------- -------------- ---------- ---------- ----------
    LIBM    CM_LIBM.TXT          12345678                5          4          2
    
  • Query based ViewObject does pull not all attributes, when the query has 'WITH' clause

    Hello

    12.1.2 and 12.1.3 JDeveloper

    When we try to create a custom query based ViewObject, and the query clause of "with."

    So not all the columns selected in the query are appearing as attributes of the View object in the wizard.

    This is the query. And it performs very well in Toad.

    WITH dept_count AS)

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id)

    SELECT e.first_name AS employee_name,

    DC1.dept_count AS emp_dept_count,

    m.first_name AS manager_name,

    DC2.dept_count AS mgr_dept_count

    E employees,

    dept_count dc1,

    m employees,

    dept_count dc2

    WHERE e.department_id = dc1.department_id

    AND e.manager_id = m.employee_id

    AND m.department_id = dc2.department_id;

    Only the EmployeeName attribute is extracted from the query. It does not show the rest of the attributes in the VO Wizard.

    VO.png

    (I also tried to create a VO from the EntityObject class and make it editable as false, even in this case all attributes are not displayed.)

    I was wondering if something changed in 12 c?

    It works in 11.1.1.7

    (A friend of mine just asked me this).

    Thanks for any help.

    Sameer

    Jdev dislikes the syntax

    You can rewrite as

    SELECT e.first_name AS employee_name,

    DC1.dept_count AS emp_dept_count,

    m.first_name AS manager_name,

    DC2.dept_count AS mgr_dept_count

    E employees,

    (

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id) dc1,.

    m employees,

    (

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id) dc2

    WHERE e.department_id = dc1.department_id

    AND e.manager_id = m.employee_id

    AND m.department_id = dc2.department_id

    who must work and give you the same result.

    Timo

  • [JDev ADF] How 1) auto - submit search Query Panel when loading the page and 2) 'secretly' proceed to the query a param

    Hello

    in my page, there is a "query with table Panel" created from all the "named criteria | All the attributes of a"of a display object.

    The request of this display object has in its where clause 1 param required.

    When JDeveloper creates the "query with table Panel" it adds to the search also fields that the param required of the View object.

    The user doesn't have to choose the value of the param: I secretly turn the param to query and to hide the search field in the "query with table Panel".

    The query must always be performed with the param I secretly put (reading the value of a managed bean).

    You kindly help me?

    Thank you

    F.

    For this you must intercept the query and add your parameter. You can use the criteria to view "All searchable attributes" for this because this IC is to build implicit and you cannot change it. However, you can create your own CV and imitate the "all attributes searchable" vc. In the t create a new Victoria Cross and all all the attributes of the query itself. One you don't want to see you can hide (like the rohanwalia post).

    Then, you must use the technique described in this blog https://blogs.oracle.com/aramamoo/entry/interpret_af_query_s_queryevent but instead to display the context menu, you set the bean to your hidden setting viewcriteria line.

    Timo

  • Need help to write the query to extract the value of the previous row - Lag not help


    Hello

    I created follwing table.

    Create table test

    (number of fi,

    number of fo_fv

    number of jup_fv

    action varchar2 (10)

    );

    insert into TEST(1,1,1,'LOAD');

    Insert into TEST (2, NULL, 2, "ROLL");

    insert into TEST(3,,3,'ROLL');

    insert into TEST(4,,4,ROLL);

    insert into TEST (5,2,5,LOAD);

    I want the result of the query as below:

    FI FO_FV JUP_FV ACTION

    -------------------------------------------------------------------

    1          1                    1                    LOAD

    2          1                    2                    ROLL

    3          1                    3                    ROLL

    4          1                    4                    ROLL

    5          2                    5                    LOAD

    Help, please.

    Thank you!

    SQL > select fi
    2, max (fo_fv) on fo_fv (fi control)
    3, jup_fv
    4, action
    5 of the test;

    FI FO_FV JUP_FV ACTION
    ---------- ---------- ---------- ----------
    1 1 1 LOAD
    ROLL OF 2 1 2
    3 1 3 ROLL
    4 1 4 ROLL
    5 2 5 LOAD

    OR

    SQL > select *.
    2 test
    model 3
    Dimension 4 by (fi)
    5 measures (fo_fv, jup_fv, action)
    6 rules
    7   (
    8 fo_fv [any] = case when fo_fv [cv ()] is null
    9. can fo_fv [cv () - 1]
    10 fo_fv [cv () else]
    11 end
    (12);

    FI FO_FV JUP_FV ACTION
    ---------- ---------- ---------- ----------
    1 1 1 LOAD
    ROLL OF 2 1 2
    3 1 3 ROLL
    4 1 4 ROLL
    5 2 5 LOAD

Maybe you are looking for