Can I rewrite the following query without using Row_number() function ??!!

Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
The query is supposed to pull out the records whose CODE is not NULL and has most
recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
SELECT a.* FROM
(SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
ORDER BY b.UPDATE_DATE DESC) AS Rno
FROM
SELECT *
FROM SHYNCRO WHERE CODE IS NOT NULL
)b
)a
WHERE a.Rno = 1

Hi,
You didn't write over 150 lines of code and then start testing it, did you?
Don't.
Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
You may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Can u write the following query without using group by clause

    select sp.sid, p.pid, p.name from product p, supp_prod sp
    where sp.pid= p.pid and
    sp.sid = ( select sid from supp_prod group by sid
    having count(*) =(select count(*) from product));
    thru this, we retrieving all the products delivered by the supplier.
    Can you write the following query without using the group by clause

      select sp.sid, p.pid, p.name
        from product p, supp_prod sp
       where sp.pid= p.pid the above query will still retrieve all the products supplied by the supplier. sub-query is not necessary.
    maybe if you can post some sample data and output will help us understand what you want to achieve.

  • How Can I make the following query faster

    Hi Guru
    I want your valuable suggestion to make the following query faster.I did not write all required columns list. I gave here all those columns where I have conditon like decode,case when,or subquery
    (SELECT CASE WHEN REPORTED_BY IS NULL THEN
              (SELECT INITCAP(EMP_NAME) FROM HR_EMP WHERE EMP_NO = M.EMP_NO_RADIO)
         ELSE (SELECT INITCAP(EMP_NAME) FROM HR_EMP WHERE EMP_NO = M.REPORTED_BY) END RADIOLOGIST_NAME,
         (SELECT TEAM_NAME FROM DC_TECHTEAMMST WHERE TEAM_NO = M.GROUP_NO) GROUP_NAME,
         CASE WHEN M.RESULT_ENTRY_LOCK_BY IS NOT NULL THEN 'R'
    WHEN M.REPORT_DONE = 'D' THEN 'D'
    WHEN M.REPORT_DONE = 'P' THEN 'P'
    WHEN M.REPORT_DONE = 'F' THEN 'F'
         WHEN NVL(M.IMG_CAPTURED,'X') NOT IN ('B','Y') OR M.QA_RESULT = 'F' THEN 'S'
    WHEN NVL(M.IMG_CAPTURED,'X') IN ('B','Y') AND NVL(M.QA_RESULT,'X') NOT IN ('B','P') THEN 'Q'
         wHEN NVL(M.IMG_CAPTURED,'X') IN ('B','Y') AND NVL(M.QA_RESULT,'X') IN ('B','P') THEN 'C'
    END STATUS,
         (SELECT DECODE(NVL(V.DELIVERY_STATUS,'N'),'E',3,'U',2,1)
              FROM FN_VOUCHERCHD V WHERE V.VOUCHER_NO = M.VOUCHER_NO AND V.ITEM_NO = M.TEST_NO) DELIVERY_STATUS,
         trunc((start_time-order_end)*24,0)||' hr'||':'||
         decode(length(trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0)),2,to_char(trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0))
              ,1,to_char('0'||trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0)))||' mi' duration_order_capture,
         DECODE(R.CONFIDENTIAL_PATIENT,'Y','*',NVL(R.NAME,R.name_lang_name||' '||R.name_lang_fname)) PAT_NAME,
         FNC_PATIENTAGE(R.REG_NO,'',R.CONFIDENTIAL_PATIENT) pat_age,
         DECODE(R.CONFIDENTIAL_PATIENT,'Y','*',R.PATIENT_SEX) PAT_SEX
    FROM DC_MODALITYAPPOINTMENT M,DC_TESTMST T,OP_REGISTRATION R
    WHERE M.ACCESSION_NO IS NOT NULL AND NVL(M.CANCEL_FLAG,'N') = 'N'
    AND (NVL(T.SP_GEN,'S') = 'S' OR NVL(M.DOC_REQ_GEN,'N') = 'Y')
    AND M.TEST_NO IS NOT NULL AND M.TEST_NO = T.TEST_NO AND M.REG_NO = R.REG_NO)
    How can I make the above query faster.
    Query condition or indexing whatever is preferable please guide me.
    The approximate data of tables
    DC_MODALITYAPPOINTMENT 2,000,000
    A lot of updating is going on some columns of this table.all columns are not in the select list, Insertion is happend in batch process by back-end trigger of another table.
    Primary key based one column,
    OP_REGISTRATION 500,000
    Daily insertion on this table around 500 records,updation is not much.
    Primary key based one column 'reg_no'
    DC_TESTMST
    Total records of this table not more than 1500.This is setup table. Insertion and updation is not much on this table also
    I have to create a view based on this query .
    and I have to create another view to serve another purpose.
    In the 2nd view I need this query as well as I need another query by using union all operator based on a table(dc_oldresult)
    which have 1,600,000 records.There is no DML on this table
    SELECT      NVL((SELECT USER_DEFINE_TEST_NO FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1 ),SV_ID) USER_D_EXAM_NO,
    (SELECT TEST_TYPE FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1 ) EXAM_TYPE,
         NVL((SELECT TEST_NAME FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1),'Exam Code: '||sv_id) EXAM_NAME,
         (SELECT PAT_NAME FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_NAME,
         (SELECT PAT_AGE FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_AGE,
         (SELECT PAT_SEX FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_GENDER
    FROM DC_OLDRESULT
    WHERE HN IS NOT NULL AND SV_ID IS NOT NULL AND UPPER(ACTIVE) = 'TRUE'
    Should I make join DC_OLDRESULT, OP_REGISTRATION and DC_TESTMST? or The eixisting subquery is better?
    I use OP_REGISTRATION and DC_TESTMST in both query
    Thanks in advance
    Mokarem

    When your query takes too long ...

  • WITHOUT USING ROW_NUMBER FUNCTIONS IN T-SQL

    INPUT:-
    CUST_ID
    GIFT_ID
    100
    10
    100
    20
    100
    30
    200
    10
    200
    20
    200
    30
    300
    20
    OUTPUT:-
    CUST_ID
    GIFT_ID
    SEQ
    100
    10
    1
    100
    20
    2
    100
    30
    3
    200
    10
    1
    200
    20
    2
    200
    30
    3
    300
    20
    1
    santoshbangalore

    THANK YOU SO MUCH FOR YOUR ANS? BUT MY INPUT TABLE A CONTAIN ONLY TWO COLUMN'S 
    CUST_ID,GIFT_ID
    AND IN OUT PUT I NEED THE ABOVE OUTPUT WITH 
    CUST_ID,GIFT_ID,ROW_NUMBER AS SHOWN ABOVE?
    santoshbangalore

  • Query without using connect by

    Hi Guys,
    I need to rewrite the following query without a connect by command. Is there a way to do this?
    [code]
    SELECT DISTINCT *
      FROM serial_structure_table str,
           serial_catalog_table   psc,
           serial_table           sop,
           life_serials_table     lls,
           part_table             mp,
           serial_parts_table     vs,
           events_table           pe,
           task_table             lmt
    WHERE str.part_no       = psc.part_no
    AND   str.serial_no     = psc.serial_no
    AND   str.part_no       = sop.part_no(+)
    AND   str.serial_no     = sop.serial_no(+)
    AND   str.part_no       = lls.part_no(+)
    AND   str.serial_no     = lls.serial_no(+)
    AND   str.part_no       = vs.part_no
    AND   str.serial_no     = vs.serial_no
    AND   mp.maint_prog     = vs.maint_prog_id(+)
    AND   mp.maint_prog     = vs.maint_prog_rev(+)
    AND   mp.part_no        = vs.part_no(+)
    AND   mp.maint_group    = vs.maint_group(+)
    AND   str.part_no       = pe.part_no(+)
    AND   str.serial_no     = pe.serial_no(+)
    AND   str.serial_no     = lmt.serial_no(+)
    AND   str.part_no       = lmt.part_no(+)
    AND   mp.maint_code     = lmt.maint_code
    AND   str.parent_seq_no IS NOT NULL
    AND   str.seq_no IN (SELECT seq_no FROM serial_table
                          START WITH seq_no = (SELECT vss.seq_no
                                               FROM serial_structure_table vss, vehicle_serial_table vehicle
                                               WHERE vss.part_no      = vehicle.part_no
                                               AND vss.serial_no      = vehicle.serial_no
                                               AND vehicle.vehicle_id = '120')
                          CONNECT BY PRIOR seq_no = parent_seq_no)
    [/code]
    Many Thanks,
    Napster

    Hi Frank,
    This query which fetches a data set to a report... So when executing this query in the report I will need to have a sql expression something like below...
    select *
    from MY_VIEW
    where vehicle.vehicle_id = '&Vehicle_Id'
    When the above is run user will be asked to insert a vehicle id and that will be the user input for my sql statement... (I inserted the value 120 here just for the testing purpose). In here I will need to create a view (something like MY_VIEW which consist of the entire sql expression) as long sql expressions are not supported in our tool. So I have to compile a view with the results set without the connect by clause...
    Just let me know if it is still not clear..
    Thanks
    Napster

  • How can i fetch records from 3 tables in a single query  without using join

    Hi.
    Can any body please tell me <b>How can i fetch records from 3 tables with a single query  without using joins</b>
    Thanx
    prabhudutta

    Hi Prabgudutta,
    We can fetch the data by using the views concept.
    Go throuth this info we can know the how to create view and same like database table only we can fetch the data.
    Views conatin the data at runtime only.
    Four different view types are supported. These differ in the
    way in which the view is implemented and in the methods
    permitted for accessing the view data.
    Database views are implemented with an equivalent view on
    the database.
    Projection views are used to hide fields of a table (only
    projection).
    Help views can be used as selection method in search helps.
    Maintenance views permit you to maintain the data
    distributed
    on several tables for one application object at one time.
    step by step creation of Maintenance view:
    With the help of the table maintenance generator, you are able to maintain the ENTRIES of the table in SM30 transaction.
    It can be set in transaction SE11 - Tools - Table maintenance generator.
    Table maintanance Generator is used to manually input values using transaction sm30
    follow below steps
    1) go to se11 check table maintanance check box under attributes tab
    2) utilities-table maintanance Generator-> create function group and assign it under
    function group input box. Also assign authorization group default &NC& .
    3) select standard recording routine radio in table table mainitainence generator to move table
    contents to quality and production by assigning it to request.
    4) select maintaience type as single step.
    5) maintainence screen as system generated numbers this dialog box appears when you click on create button
    6) save and activate table
    One step, two step in Table Maintenance Generator
    Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.
    Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.
    SM30 is used for table maintenance(addition or deletion of records),
    For all the tables in SE11 for which Table maintenance is selected , they can be maintained in SM30
    Sm30 is used to maintain the table ,i.e to delete ,insert or modify the field values and all..
    It creates the maintenance screen for u for the aprticular table as the maintenance is not allowed for the table..
    In the SE11 delivery and maintenance tab, keep the maintenance allowed..
    Then come to the SM30 and then enter the table name and press maintain..,
    Give the authorization group if necessary and give the function group and then select maintenance type as one step and give the screen numbers as system specified..
    Then create,,,
    Then u will able to see the maintenance view for the table in which u can able to insert and delete the table values...
    We use SM30 transaction for entering values into any DB table.
    First we create a table in SE11 and create the table maintenance generator for that Table using (utilities-> table maintenance generator) and create it.
    Then it will create a View.
    After that from SM30, enter the table name and Maintain, create new entries, change the existing entries for that table.
    Hope this resolves your query.
    Reward all the helpful answers.
    Rgds,
    P.Naganjana Reddy

  • How can i construct this query without using CASE statement?

    I've a following code. I'm using this script in Hibernet. So, i cannot use CASE there. Because, hibernet doesn't support case in select statement. How can i construct the same thing which will give me the same result without using CASE?
    SELECT ofc.FLT_LCL_ORIG_DT
         , ofc.CARR_IATA_CD
         , ofc.FLT_NBR
         , ofc.ORIG_ARPT_CD
         , ofc.DEST_ARPT_CD
         , sum( ofc.CNCT_PSGR_CNT) AS BOOKED_CNCT_PSGR_CNT
         , sum( CASE WHEN o.fsdr_mrkt_cd = 'D' AND d.fsdr_mrkt_cd = 'D'           THEN '0'
            ELSE to_char(ofc.CNCT_PSGR_CNT,'99')                             END ) AS BOOKED_INTL_CNCT_PSGR_CNT
         , sum(CASE WHEN o.fsdr_mrkt_cd||d.fsdr_mrkt_cd = 'DD'
                    THEN '0'
            ELSE to_char(ofc.CNCT_PSGR_CNT,'99')
            END) AS NEW_BCNT
    FROM OPS_FLT_CNCT ofc
                        , STN o
                        , STN d
                    WHERE ofc.CNCT_ORIG_ARPT_CD = o.STN_CD
                      AND ofc.CNCT_DEST_ARPT_CD = d.STN_CD
                     -- AND TRUNC(ofc.FLT_LCL_ORIG_DT) = trunc(to_date('22-MAY-2007','DD-MON-YYYY'))
                      AND ofc.CARR_IATA_CD = 'UA'
                      AND ofc.FLT_NBR = '1218'
                      AND ofc.ORIG_ARPT_CD = upper('DEN')                AND ofc.DEST_ARPT_CD = upper('IAD')                  GROUP BY ofc.FLT_LCL_ORIG_DT
                           , ofc.CARR_IATA_CD
                           , ofc.FLT_NBR
                           , ofc.ORIG_ARPT_CD
                           , ofc.DEST_ARPT_CD ;And, the output look like this --
    FLT_LCL_O CARR FLT_N ORI DES BOOKED_CNCT_PSGR_CNT BOOKED_INTL_CNCT_PSGR_CNT   NEW_BCNT
    22-MAY-07 UA   1218  DEN IAD                    9                         0          0
    23-MAY-07 UA   1218  DEN IAD                    1                         0          0
    24-MAY-07 UA   1218  DEN IAD                    2                         1          1
    25-MAY-07 UA   1218  DEN IAD                    1                         0          0Thnaks in advance for reply.
    Regards.
    Satyaki De.
    #####

    2 ideas:
    1. Inline function to perform the CASE funcionaltity for you
    2. Piplelined function to generate the entire dataset
    Both will be slower than just using CASE in a query, but we're working around big constraints

  • Needs  help to retrive the last row in a  select query without using rownum

    Hi ,
    i need to retrive the last row from the select sub query without using rownum.
    is there any other way to retrive the last row other than the below query.
    is that the ROWNUM=1 will always retrive the 1 row of the select query ?
    select from*
    *(select ename from employee where dept_id=5 order by desc) where rownum=1;*
    Please advise.
    thanks for your help advance,
    regards,
    Senthur

    957595 wrote:
    Actually my problem is ithat while selecting the parents hiearchy of the child data using
    CONNECT BY PRIOIR query
    I need the immediate parent of my child data.
    For example my connect BY query returns
    AAA --- ROOT
    BBB --PARENT -2
    CCC --PARENT-1
    DDD IS my input child to the connect by query
    Immediate parent of my child data "DDD" ---> CCC(parent -1)
    i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
    I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
    So confusing with using this rownum in my query.
    Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
    you can select the PRIOR values to get the parent details if you want...
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
      2  from emp
      3  connect by mgr = prior empno
      4* start with mgr is null
    SQL> /
         EMPNO ENAME                                 MGR
          7839 KING
          7566   JONES                              7839
          7788     SCOTT                            7566
          7876       ADAMS                          7788
          7902     FORD                             7566
          7369       SMITH                          7902
          7698   BLAKE                              7839
          7499     ALLEN                            7698
          7521     WARD                             7698
          7654     MARTIN                           7698
          7844     TURNER                           7698
          7900     JAMES                            7698
          7782   CLARK                              7839
          7934     MILLER                           7782
    14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data)

  • Can we rollback the update query using Transaction?

    Can we rollback the Update query by writing the update query with in the transaction, as i am implementing different update queries, sometimes I am mistakenly updating the table without where criteria, which is messing up the table. Is there anyway where
    we can write the update query within a transaction and rollback that particular update query which I am writing. I do have a backup table, but that wont be useful because we are doing lot of updates in a span of minutes. I researches about Apex Sql logs too,
    but we do not have access to download such tools. So, can anyone give me a good solution for this?

    Sure, if you use transaction like this
    begin transaction
    update 1
    update 2
    rollback transaction
    both updates will be rollbacked.
    If you want to always be sure about rows you're about to change, always first try with SELECT statement and put each individual UPDATE into separate transaction with rollback at the end, e.g.
    begin transaction
       select ... where some condition
       update . where same condition
       select ... where same condition to verify update
    rollback transaction
    If your last select showed correct info, change ROLLBACK into COMMIT and re-run that script again to perform the actual update.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • I want single update query without use the function.

    I want to update sells_table selling_code field with max date product_code from product table.
    In product table there is multiple product_code date wise.
    I have been done it with below quey with the use of function but can we do it in only one update query
    without use the function.
    UPDATE sells_table
    SET selling_code = MAXDATEPRODUCT(ctd_vpk_product_code)
    WHERE NVL(update_product_flag,0) = 0 ;
    CREATE OR REPLACE FUNCTION HVL.maxdateproduct (p_product IN VARCHAR2) RETURN NUMBER
    IS
    max_date_product VARCHAR2 (100);
    BEGIN
    BEGIN
    SELECT NVL (TRIM (product_code), 0)
    INTO max_date_product
    FROM (SELECT product_code, xref_end_dt
    FROM product
    WHERE TO_NUMBER (p_product) = pr.item_id
    ORDER BY xref_end_dt DESC)
    WHERE ROWNUM = 1; -- It will return only one row - max date product code
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN 0;
    END;
    RETURN max_date_product;
    END maxdateproduct;
    Thanks in Advance.

    Hi,
    Something like this.
    update setlls_table st
            set selling_code =(select nvl(trim(product_code)) from 
                                  (select product_code
                                          , rank() over (partition by item_id order by xref_end_dt DESC) rn
                                       from product
                                   ) pr
                                   where rn =1
                                         and pr.item_id = st.ctd_vpk_product_code
                               ) where NVL(update_product_flag,0) = 0 ;As such not tested due to lack of input sample.
    Regards
    Anurag Tibrewal.

  • How can i know if my query is using the index ?

    Hello...
    How can i know if my query is using the index of the table or not?
    im using set autotrace on...but is there another way to do it?
    thanks!
    Alessandro Falanque.

    Hi,
    You can use Explain Plan for checking that your query is using proper index or not. First you need to check that Plan_table is installed in your database or not. If it is not there THEN THE SCRIPT WILL BE LIKE THIS:
    CREATE TABLE PLAN_TABLE (
    STATEMENT_ID VARCHAR2 (30),
    TIMESTAMP DATE,
    REMARKS VARCHAR2 (80),
    OPERATION VARCHAR2 (30),
    OPTIONS VARCHAR2 (30),
    OBJECT_NODE VARCHAR2 (128),
    OBJECT_OWNER VARCHAR2 (30),
    OBJECT_NAME VARCHAR2 (30),
    OBJECT_INSTANCE NUMBER,
    OBJECT_TYPE VARCHAR2 (30),
    OPTIMIZER VARCHAR2 (255),
    SEARCH_COLUMNS NUMBER,
    ID NUMBER,
    PARENT_ID NUMBER,
    POSITION NUMBER,
    COST NUMBER,
    CARDINALITY NUMBER,
    BYTES NUMBER,
    OTHER_TAG VARCHAR2 (255),
    PARTITION_START VARCHAR2 (255),
    PARTITION_STOP VARCHAR2 (255),
    PARTITION_ID NUMBER,
    OTHER LONG,
    DISTRIBUTION VARCHAR2 (30))
    TABLESPACE SYSTEM NOLOGGING
    PCTFREE 10
    PCTUSED 40
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 10240
    NEXT 10240
    PCTINCREASE 50
    MINEXTENTS 1
    MAXEXTENTS 121
    FREELISTS 1 FREELIST GROUPS 1 )
    NOCACHE;
    After that write the following command in the SQL prompt.
    Explain plan for (Select statement);
    Select level, SubStr( lpad(' ',2*(Level-1)) || operation || ' ' ||
    object_name || ' ' || options || ' ' ||
    decode(id, null , ' ', decode(position, null,' ', 'Cost = ' || position) ),1,100)
    || ' ' || nvl(other_tag, ' ') Operation
    from PLAN_TABLE
    start with id = 0
    connect by
    prior id = parent_id;
    This will show how the query is getting executed . What are all the indexes it is using etc.
    Cheers.
    Samujjwal Basu

  • Can somebody can tell me is CC for team can support to save the files in the local area without using the cloud ?

    Can somebody can tell me is CC for team can support to save the files in the local area without using the cloud ?

    The desktop applications are still installed on your computer, and the files are also saved on your computer.
    Optionally you can upload files with a browser to https://creative.adobe.com/files, or sync up files using the file sync that is part of the Creative Cloud desktop application. The online file storage is private to you, no one else can see it your files.
    If you do want to share your files there are two options:
    You can Collaborate, which is sharing a folder with another Adobe ID. Only the person you collaborate with can see the folder.
    You can use Send Link to send a publicly accessible url to a file or folder.

  • Problem in finding Exact result by using the following Query

    Hello,
    I am finding difficulty in producing the required result by using the following Query in Reports 6i
    (Note: - The query actual output and the required output are as follows: -)
    SELECT
    DISTINCT
    SH.S_HEAD_CODE,
    B.BILL_ID,
    B.SANCTION_DATE,
    E.EMP_NAME,
    E.EMP_DESIGNATION,
    B.TOTAL_BILL,
    NVL((SH.INITIAL_ALLOCATION-B.TOTAL_BILL), 0) BALANCE
    FROM BILL B, PARAMETERS P,SUB_HEAD SH, EMPLOYEES E, BILL_DETAIL BD
    WHERE
    SH.S_HEAD_CODE=B.S_HEAD_CODE
    AND B.S_HEAD_CODE=BD.S_HEAD_CODE
    AND B.EMP_ID_NO=E.EMP_ID_NO
    AND B.BILL_ID=BD.BILL_ID
    The Output of the above query is as follows: -
    Let say we have Total Amount Sanctioned Rs. 15,000,00/-
    Name Total Bill (Rs.) Balance (Rs.)
    Sohail 7147 1492853
    Saqib 2131 1497869
    Amir 6802 1493198
    Shafiq 1214 1498786
    Note:- In the above output the above query is subtracting the current balance from Total Sanctioned Amount (Rs. 1500000) each time, but
    it should actually subtract the current bill amount from the previous balance like the below said result.
    Name Total Bill (Rs.) Balance (Rs.)
    Sohail 7147 1492853 {Previous Balance - Current Bill Amount (1500000-7147) }........ The previous balance was actual amount Rs. 1500000
    Saqib 2131 1490722 {Previous Balance - Current Bill Amount (1492853 - 2131)}
    Amir 6802 1483920 {Previous Balance - Current Bill Amount (1490722 - 6802)}
    Shafiq 1214 1482706 {Previous Balance - Current Bill Amount (1483920 - 1214)}
    Results Continue...........................
    Please help me to solve this problem.
    Thank you in advance

    just check if this meets your requirements,
    SQL>
    SQL> With t As
      2  (
      3  Select 'Sohail' c1 ,7147 c2 ,1492853 c3 From dual Union All
      4  Select 'Saqib'   ,2131 ,1497869         From dual Union All
      5  Select 'Amir'    ,6802 ,1493198         From dual Union All
      6  Select 'Shafiq' ,1214 ,1498786          From dual
      7  )
      8  Select c1,
      9         c2,
    10         prv_amt - c2 current_amt
    11  From
    12  (
    13  Select c1,
    14         c2,
    15         c3,
    16         lag(c3,1,1500000) over(Order By c3) prv_amt
    17  From t
    18  );
    C1             C2 CURRENT_AMT
    Sohail       7147     1492853
    Amir         6802     1486051
    Saqib        2131     1491067
    Shafiq       1214     1496655
    SQL>

  • How can i ge into the app store without using a credit card?

    How do i get into the app store without using a credit card?

    Unless you can find an item in the store that costs the same as your balance then you will need to contact iTunes Support and ask them if they can remove the balance : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • How can I back into the main screen without using the activator bottom?

    How can I back into the main screen without using the activator bottom?

    I assume you mean the HOME button. You cannot. The HOME button is the only way to exit an app.

Maybe you are looking for

  • How do I remove my credit card from account?

    How do I?

  • Disparity between size of time machine backup and my Hard drive

    The lap top is holding 53 gb on the disk, but time machine is only holding 44gb. Is that ok? How can i be sure that the initial backup went ok. I had woken up this morning and got an error message that the backup could not be completed. However furth

  • Is it possible to add the exit command to a button in ALV OO toolbar

    Hi ABAP folks, is there are a way to add the exit command to a button of an ALV toolbar (like in the GUI status)? I want to prevent the field validations of a dynpro field at PAI. Thanks and regards, Martin

  • Failed to Refresh Dynamic Report

    Hi Gurus, I'm having issue refreshing a report with dynamic selection of entities. There are no error message but it just didn't list out all the entity I've selected. The same report has no issue listing out the entities in 2 other computers which I

  • Camera auto focus

    I am so mad, I have only had my phone 2 weeks, and the auto focus has stopped working.  I have tried to take auto focus off then  on and rebooted the phone with  taking the battery out.  Nothing has worked.  Has anyone heard about this problem?