Down to Top approach query help..

Dear All,
Best wishes,
actaully my table has 4 columns.
like
control no,Po Number,Amend No,Factor.
scenario is : each control no ---> can have multiple PO numbers ---> each po can have multiple amend ----> each amend have different factor..
Now i want to see result like branch ---> Tree ( down to up approach data) ..
like count of each casual factor --- for each amend ---how many amend for po and min and max of amend value ---> how many po for control..
Please suggest some query..
thanks you in advance
Prasanth

Please consider the following when you post a question.
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
      select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
      union all
      select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
  from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id   sum_qty   count_inv
1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
   {thread:id=501834} and {thread:id=863295}.
   Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
   So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Need help for top n query

    Hi,
    I want to show top 3 salary records from emp table and I am using below query in oracle * plus. However I am getting an error saying, "FROM keyword not found where expected". I am not getting what mistake I am doing while writing this query. Can someone plz advice?
    Query:
    Select top 3 sal from emp;
    Thanks in advance.

    Hi,
    In Oracle, there is no TOP keyword. The usual way to do a top-N query in Oracle is to use an analytic function, such as RANK:
    WITH     got_r_num     AS
         SELECT     sal
         ,     ename, empno, ...     -- whatever columns you want
         ,     RANK () OVER (ORDER BY sal DESC)    AS r_num
         FROM     scott.emp
    SELECT       sal
    ,       ename, empno, ...     -- if wanted
    ,       r_num                -- if wanted
    FROM       got_r_num
    WHERE       r_num     <= 3
    ORDER BY  sal
    ;Depending on how you want to handle ties, ypu may want to add tie-breaking columns to the end of the analytic ORDER BY clause, and/or use ROW_NUMBER instead of RANK.

  • Query Help on RowNum

    Hi ,
    Please help me on this…
    Select * from EMP where Emp_Type in (1, 2 ) order by Emp_Type;
    the above query gives me the result like this
    Emp_Id Name Emp_Type
    100     asas     1
    101 dsds     1
    122     gfgf     1
    154     ytytyt     1
    125     uyuy     1
    153     reree     2
    154     ytytt     2
    600     trtrtr     2
    700 gfghf 2
    If I pass the Start with num 2 and give 3 as number of records to be displayed. I need to retrieve only the following rows..
    Emp_Id Name Emp_Type
    101 dsds     1
    122     gfgf     1
    154     ytytyt     1
    154     ytytt     2
    600     trtrtr     2
    700 gfghf 2
    If the Emp_Type was only one ie,
    Select * from EMP where Emp_Type in (1) order by Emp_Type;
    I know I can get it done by using TOP-N query method
    select * from
    (Select rownum RWnum ,A.* From
    (Select * from EMP where Emp_Type in (1) order by Emp_Type) A
    where rownum<=4)
    where RWnum>=2;
    but I am stuck up with doing for multiple Emp_Type..
    here the Emp_Type could be more than two values…
    Regards
    Ben Narendran

    Hi muthukumar S,dnikiforv,Vsugur
    Thanks a lot for the analytical function ROW_NUMBER().
    But still have some concern about the query you have given..
    Let me first run the inner query.
    SQL>
    SQL > Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
    EMP e where Emp_Type in (1, 2 ) order by Emp_Type;
    EMP_ID NAME EMP_TYPE RNO
    154 aaa 1 1
    101 dsds 1 2
    122 gfgf 1 3
    125 aaa 1 4
    100 asas 1 5
    700 gfghf 2 1
    600 trtrtr 2 2
    153 reree 2 3
    If I give the range from 2 and 3 am suppose to get the following rows.
    EMP_ID NAME EMP_TYPE RNO
    101 dsds 1 2
    122 gfgf 1 3
    600 trtrtr 2 2
    153 reree 2 3
    when I run the query you sent am getting the following result..
    SQL > select * from
    (Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
    EMP e where Emp_Type in (1, 2 ) order by Emp_Type)
    where rno between 2 and 3;
    EMP_ID NAME EMP_TYPE RNO
    101 dsds 1 2
    154 aaa 1 3
    600 trtrtr 2 2
    700 gfghf 2 3
    Here the company id 700 is not suppose to come, instead I have to get 153.
    So I made some changes in the view and , wrote it like this
    SQL> select * from
    (select rno Rwnum,Outer_Qry.* from
    (select Real_Qry.*,row_number() over(partition by emp_type order by emp_type)rno
    from
    (select emp_id,name,emp_type from emp where emp_type in (1,2) order by emp_type)Real_Qry)Outer_Qry
    where rno <=3)
    where Rwnum >=2;
    RWNUM EMP_ID NAME EMP_TYPE RNO
    2 101 dsds 1 2
    3 122 gfgf 1 3
    2 600 trtrtr 2 2
    3 153 reree 2 3
    I guess now am getting the correct result..
    Please correct me if I am wrong, and please let me know if I have to make any modification on it..
    Thanks and regards
    Ben

  • Displaying the result of the TOP N query

    Hi all,
    we are facing a challenging task were we are going to build a query that gives the answer on the question:
    How many different materials (of the top sold) represent 80% of the total sales in quantity?
    The result should of the query should be very short:
                                                                                    2002           2003             2004
    Nr of materials 
    reps 80%          432            453               499
    The query is build on a CO-PA based cube, where each line corresponds to a billing item with material and quantity.
    By using a Top 80% condition on the quantity sold keyfigure we get out the top 80% materials sold:
    Year     Material     QTYSold        QTYSold-Ranked 
    2002     Mtr0323      10000             1
             Mtr0262      9000              2
             Mtr0243      8700              3
             Mtr0763      600               423
             Result       932000            423
    2003     Mtr0123      9700              1
             Mtr0332      9100              2
             Mtr0243      8700              3
            Mtr0763      543               453
             Result       912000            453
    We would like to supress the materials and only show the result row (or the raked position of the last material).
    The problem is that the 'Calculate Single Value As' properties of a formula (or keyfigure) only applies on Displayed Data values. All tests we have done so far with 'supression of zeros' & 'always hide' has messed up or counting / ranking functions.
    Is there any function in within formulas that have same functionality like Count,Rank etc?
    Is there any other way to supress materials and only show results?
    Any suggestions are welcome!

    Irina,
    Should be achievable using exception aggregation and pre-query.
    Create a query that gives the list of material that account for 80% of the sales using condition on the sales column.
    In the second query, using exception aggregation, count the number of materials that make up this set for the year. Create a new calculated key figure with the formula as qual to sales key figure. In the properties window, press the enhance button and select count of all values in the first drop down and material in the second drop down. Filter the query on material with a characteristic variable with processing as replacement path. In the variable point it to the first query. Drilldown for this will be year.
    This will give you number of materials for one year. If you want comparitive for three years, then three pre-queries and three variables with the calculated key figure restricted to a variable pointing to one years query.
    You can use pre-calculated value sets to improve the run for the result query.
    Cheers
    Aneesh

  • Top N query giving error for oracle 8.0.6

    Dear All,
    We are executing this query SELECT XBLNR, WERKS, MATNR, MDV01, BACKFLQUANT, STATUS, SAPTIMESTAMP, PITSTIMESTAMP, PMTIMESTAMP, BATCH FROM (SELECT XBLNR, WERKS, MATNR, MDV01, BACKFLQUANT, STATUS, SAPTIMESTAMP, PITSTIMESTAMP, PMTIMESTAMP, BATCH FROM PMBPITS.PITS_UNITY WHERE STATUS = '01' ORDER BY PMTIMESTAMP) WHERE ROWNUM < 20
    on oracle 8.0.6 but this is giving the following error
    ora - 00907 missing right parenthesis error
    1. Is it that in the inner select we cannot use order by and where clause together.
    2. We also found that if we remove order by from inner select then the query is not giving error
    pls help . points will be awarded

    Hi,
    what ever the Aman said is correct. You check this is supported in 8.1.5, SQL allows you to embed the ORDER BY clause in a subquery and place the ROWNUM condition in the top-level query;
    'Top-N query' is a ORACLE 8i feature which is supported in SQL. However,
    Bug:855720 states the following:
    "PL/SQL does not support top-N queries (ORDER BY in SUBSELECT/SUBQUERY
    or VIEW. Since this feature is available in SQL, but not in PL/SQL,
    it has been logged as a Bug that will be fixed in 8.1.6."
    - Pavan Kumar N

  • Top utilising Query in SQL server

    Hi,
       Is there any query to get the top utilization query of the day?

    Hi,
    Top CPU utilizing query
    --This might take some time to give result on busy systemselect top 10
    sum(qs.total_worker_time) as total_cpu_time,
    sum(qs.execution_count) as total_execution_count,
    count(*) as number_of_statements,
    t.text
    from
    sys.dm_exec_query_stats qs
    cross apply sys.dm_exec_sql_text(qs.sql_handle) as t
    group by t.text
    order by sum(qs.total_worker_time) desc
    For memory utilization there is no perfect way to find out if query has completed. but
    sys.dm_exec_query_memory_grants would help you
    SELECT mg.granted_memory_kb, mg.session_id, t.text, qp.query_plan
    FROM sys.dm_exec_query_memory_grants AS mg
    CROSS APPLY sys.dm_exec_sql_text(mg.sql_handle) AS t
    CROSS APPLY sys.dm_exec_query_plan(mg.plan_handle) AS qp
    ORDER BY 1 DESC OPTION (MAXDOP 1)
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • How to find top utilized query for last two months in oem

    how to find top utilized query for last two months in oracle enterprise manager?

    Can you mark the thread as Helpful  and once marked the information can be reviewed by other customer for similar queries
    Regards
    Krishnan

  • Move Label From Down To Top The Frame?

    greetings all
    i want to make something like movie credits
    i have an empy frame and i have some labels
    and i want when the frame runs labels move in turn from down to top
    any ideas,how to do that?
    thanks in advance

    thanks Encephalopathic for the help
    but i have just two questions about your code:
    i don't understand what's DELTA_Y and what's it's function here:
    if (y > 0)
              y -= DELTA_Y;
    }and i have added another label and set it to be shown after the first label
    but what happens is the opposite,i don't know why?
    here's what i did:
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.Timer;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class test_timer
      private static final int Y_MAX = 300;
      protected static final int X_POS = 10;
      protected static final int DELTA_Y = 2;
      private static final int DELAY_TIME = 100;
      private static int y = Y_MAX;
      private static JPanel panel;
      public static void main(String[] args)
        JFrame frame = new JFrame("Credits");
        final JLabel label = new JLabel("Updating Component Test", JLabel.CENTER);
        final JLabel label2 = new JLabel("Statement Two", JLabel.CENTER);
        label.setFont(new Font("Courier New", Font.BOLD, 15));
        label.setSize(label.getPreferredSize());
        label.setLocation(X_POS, y);
        label.setForeground(Color.WHITE);
        label2.setFont(new Font("Courier New", Font.BOLD, 15));
        label2.setSize(label2.getPreferredSize());
        //i set the label2 to be down label1
        label2.setLocation(X_POS, y+25);
        label2.setForeground(Color.WHITE);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel = new JPanel();
        panel.setPreferredSize(new Dimension(2*Y_MAX, Y_MAX));
        panel.setLayout(null);
        panel.setBackground(Color.BLACK);
        panel.add(label);
        //i added label2 after label1
        panel.add(label2);       
        frame.add(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        new Timer(DELAY_TIME, new ActionListener()
          public void actionPerformed(ActionEvent ae)
            if (y > 0)
              y -= DELTA_Y;
              label.setLocation(X_POS, y);
              //set the new location to be less than label1 location
              label2.setLocation(X_POS,y-40);
        }).start();
    }

  • Query Help-2

    Query Help:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
    It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
    The above was my previous posting, which was not clear..so Iam restating my problem as follows....
    I have the following tables
    Customer(custID, Name, Address)
    Order(custID, OrderID, orderDate)
    CreditCard(custID, creditCard#, creditCardType)
    Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
    Order:
    100,A001,11/22/03
    100,A002,11/24/03
    100,A003,12/02/03
    CreditCard:
    100,42323232..., VISA
    100,5234234...., MASTER
    Now how can I get
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    data in minimum no. of records....
    I think I have made my query clear..
    now please help me guys...
    thanks so much for your help.

    You are right.
    But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
    Can you please help me with the query
    if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
    With the following fields in my query result,
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    from Customer, Order, CreditCard tables
    Thanks so much for your htlp

  • How to add a Font Button in the Top of the Help File

    Dear all,
    In some of the Help Files (HTML Help), i've seen a Font
    button being added in the top of the Help File (for e.g next to
    Home button)...when we click this font button, the font size of the
    Content present in the Help File Increases/decreases
    accordingly....how to add this button in our Help File.
    At present i'm creating a HTML Help using Adobe 6..Kindly let
    me know, if there are any options...
    Thanks with regards

    Hi usureka
    Take a look at the following link. It should guide you.
    click
    here
    Cheers... Rick

  • Top N query with INLIST Iterator performance problem

    I have a top N query that is giving me problems on Oracle 11.2.0.3.
    First of all, I have a query like the following (simplified from the real query, but produces the same problem):
        select /*+ gather_plan_statistics */ * from
          select rowid
          from payer_subscription ps
          where  ps.subscription_status = :i_subscription_status
          and ps.merchant_id           = :merchant_id2
          order by transaction_date desc
        ) where rownum <= :i_rowcount; This query works well. It can very efficiently find me the top 10 rows for a massive data set, using an index on merchant_id, subscription_status, transaction_date.
        | Id  | Operation                     | Name        | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
        |   0 | SELECT STATEMENT              |             |      1 |        |     10 |00:00:00.01 |       4 |
        |*  1 |  COUNT STOPKEY                |             |      1 |        |     10 |00:00:00.01 |       4 |
        |   2 |   VIEW                        |             |      1 |     11 |     10 |00:00:00.01 |       4 |
        |*  3 |    INDEX RANGE SCAN DESCENDING| SODTEST2_IX |      1 |    100 |     10 |00:00:00.01 |       4 |
        -------------------------------------------------------------------------------------------------------As you can see the estimated actual rows at each stage are 10, which is correct.
    Now, I have a requirement to get the top N records for a set of merchant_Ids, so if I change the query to include two merchant_ids, the performance tanks:
        select /*+ gather_plan_statistics */ * from
          select  rowid
          from payer_subscription ps
          where  ps.subscription_status = :i_subscription_status
              and (ps.merchant_id = :merchant_id or
                   ps.merchant_id = :merchant_id2 )
          order by transaction_date desc
        ) where rownum <= :i_rowcount;
        | Id  | Operation               | Name        | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
        |   0 | SELECT STATEMENT        |             |      1 |        |     10 |00:00:00.17 |     178 |       |       |          |
        |*  1 |  COUNT STOPKEY          |             |      1 |        |     10 |00:00:00.17 |     178 |       |       |          |
        |   2 |   VIEW                  |             |      1 |    200 |     10 |00:00:00.17 |     178 |       |       |          |
        |*  3 |    SORT ORDER BY STOPKEY|             |      1 |    200 |     10 |00:00:00.17 |     178 |  2048 |  2048 | 2048  (0)|
        |   4 |     INLIST ITERATOR     |             |      1 |        |  42385 |00:00:00.10 |     178 |       |       |          |
        |*  5 |      INDEX RANGE SCAN   | SODTEST2_IX |      2 |    200 |  42385 |00:00:00.06 |     178 |       |       |          |Notice now that there are 42K rows coming out of the two index range scans - Oracle is no longer aborting the index range scan when it reaches 10 rows. What I thought would happen, is that Oracle would get at most 10 rows for each merchant_id, knowing that at most 10 rows are to be returned by the query. Then it would sort that 10 + 10 rows and output the top 10 based on the transaction date, but it refuses to do that.
    Does anyone know how I can get the performance of the first query, when I need to pass a list of merchants into the query? I could probably get the performance using a union all, but the list of merchants is variable, and could be anywhere between 1 or 2 to several 100, so that makes that a bit unworkable.

    Across the two merchants_id's there are about 42K rows (this is in test, on Prod there could be several million). In the first query example, Oracle can answer the query in about 4 logical IOs and without even doing a sort as it uses the index to scan and get the relevant rows in Oracle.
    In the second case, I hoped it would pull 10 rows for each merchant_id and then sort the resulting 20 rows to find the top 10 ordered by transaction_date, but instead it is scanning far more rows than it needs to.
    In my example, it takes 4 logical IOs to answer the first query, but ~ 170 to answer the second, while I think it is achievable in 8 or so. For example, this query does what I want, but it is not a feasible option due to how many merchant_id's I may have to deal with:
    select /*+ gather_plan_statistics */ *
    from
      select *
      from 
        select * from
          select  merchant_id, transaction_date
          from payer_subscription ps
          where  ps.subscription_status = :i_subscription_status
          and ps.merchant_id = :merchant_id
          order by transaction_date desc
        ) where rownum <= :i_rowcount
        union all
        select * from  
          select  merchant_id, transaction_date
          from payer_subscription ps
          where  ps.subscription_status = :i_subscription_status
          and ps.merchant_id = :merchant_id2
          order by transaction_date desc
        ) where rownum <= :i_rowcount
      ) order by transaction_date desc
    ) where rownum <= :i_rowcount;
    | Id  | Operation                          | Name        | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT                   |             |      1 |        |     10 |00:00:00.01 |    6 |          |       |          |
    |*  1 |  COUNT STOPKEY                     |             |      1 |        |     10 |00:00:00.01 |    6 |          |       |          |
    |   2 |   VIEW                             |             |      1 |     20 |     10 |00:00:00.01 |    6 |          |       |          |
    |*  3 |    SORT ORDER BY STOPKEY           |             |      1 |     20 |     10 |00:00:00.01 |    6 |  2048 |  2048 | 2048  (0)|
    |   4 |     VIEW                           |             |      1 |     20 |     20 |00:00:00.01 |    6 |          |       |          |
    |   5 |      UNION-ALL                     |             |      1 |        |     20 |00:00:00.01 |    6 |          |       |          |
    |*  6 |       COUNT STOPKEY                |             |      1 |        |     10 |00:00:00.01 |    3 |          |       |          |
    |   7 |        VIEW                        |             |      1 |    100 |     10 |00:00:00.01 |    3 |          |       |          |
    |*  8 |         INDEX RANGE SCAN DESCENDING| SODTEST2_IX |      1 |    100 |     10 |00:00:00.01 |    3 |          |       |          |
    |*  9 |       COUNT STOPKEY                |             |      1 |        |     10 |00:00:00.01 |    3 |          |       |          |
    |  10 |        VIEW                        |             |      1 |     11 |     10 |00:00:00.01 |    3 |          |       |          |
    |* 11 |         INDEX RANGE SCAN DESCENDING| SODTEST2_IX |      1 |    100 |     10 |00:00:00.01 |    3 |          |       |          |
    ---------------------------------------------------------------------------------------------------------------------------------------This UNION ALL query completes in 6 logical IOs - the original query I posted with 2 IDs takes 178 to return the same results.

  • I performed a software update and the system is installing an update but it has been running for over 24hrs and keeps saying "This may take a few minutes, don't shut down your computer" Can anyone help?

    I performed a software update and the system is installing an update but it has been running for over 24hrs and keeps saying "This may take a few minutes, don't shut down your computer" Can anyone help?

    Hello cor-el, thanks for your reply. I changed my settings for downloads to desktop and it has appeared on there. When I double click I am asked which program I want to open file. I click firefox and another box "opening install" says I have chosen to open the file which is an application and do I want to save it. This is the only real option so I press save file. I get a box saying this is an executable file which may contain viruses - do you want to run. I press ok and the final box showing C drive file name and desktop appears stating application not found.
    This happens the same whenever I try to install.
    To my untrained eye the application is not being recognised as an application and I cannot work out how to get it to do that.
    My plugin is still showing as out of date.
    Is there anything you could suggest. Thanks for your time.

  • I created a Pages document inserting 2 columns using 1) Inspector 2) Layout 3) columns.  How do I decrease the height of the column.  Have tried to use cursor and drag down the top border, but that does not reset the top border.

    I created a Pages document inserting 2 columns using 1) Inspector 2) Layout 3) columns.  How do I decrease the height of the column.  Have tried to use the cursor and drag down the top border, but that does not reset/decrease the top border.

    Set your columns back to one for the moment. In layout mode, insert a Text box. Place it in the upper left corner of your document, and drag down and right to the size of the container for your two columns. Click inside the Text Box, and now bump up your columns to 2. Your two columns are now contained in this resizable Text Box.

  • SQL Query Help - Is this possible or impossible????

    Hi guys,
    I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
    For example,
    I have 2 tables
    The first table is:
    1) COMPANY create table company (manufacturer varchar2(25),
                                                          date_established date,
                                                          location varchar2(25) );My sample test date is:
    insert into company values ('Ford', 1902, 'USA');
    insert into company values ('BMW', 1910, 'Germany');
    insert into company values ('Tata', 1922, 'India');The second table is:
    2) MODELS create table models (manufacturer varchar(25),
                                                 model varchar2(25),
                                                 price number(10),
                                                 year date,
                                                 current_production_status varchar2(1) ) ;My sample test data is:
    insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
    insert into models values ('Ford', 'Galaxy', 12000,   2008, 0);
    insert into models values ('Ford', 'Escort', 10000, 1992, 1);
    insert into models values ('BMW', '318', 17500, 2010, 0);
    insert into models values ('BMW', '535d', 32000,   2006, 0);
    insert into models values ('BMW', 'Z4', 10000, 1992, 0);
    insert into models values ('Tata', 'Safari', 4000, 1999, 0);
    insert into models values ('Tata', 'Sumo', 5500,   1996, 1);
    insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer IN ('Ford', 'BMW', 'Tata')
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCWhat I want the query to output is this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               Sumo               5500               1998          1If current_production_status is 1 it means this particular model has been discontinued
    If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
    The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
    So the query should output the one row where current_production_status is 1 for each manufacturer.
    If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
    My query as it is above will output all the records where current status is 1 or 0 like this
    com.manufacturer        com.date_established          com.location          mod.model          mod.price          mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    Tata               1922                    India               Sumo               5500               1998          1
    Ford               1902                    USA               -               -               -          0                    
    Ford               1902                    USA               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               -               -               -          0
    Tata               1922                    India               -               -               -          0However this is not what I want.
    Any ideas how I can achieve the result I need?
    Thanks!
    P.S. Database version is '10.2.0.1.0'

    Hi Vishnu,
    Karthiks query helped...
    But this is the problem I am facing...
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer = 'Ford'
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCThe value of:
    and com.manufacturer = 'Ford'will be dependent on front end user input....
    When I run the query above I get all the rows where current_production_status is either 1 or 0.
    I only require the rows where current_production_status is 1.
    So if I amend it to look like this:
         and mod.current_production_status = 1This works....
    BUT if a user now passes in more than one manufacturer EG:
    and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
    So like this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
    Thanks you so much!
    This is really driving me insane :-(

  • Can we hide filter in Search Master agreements standard top level query?

    Hi Experts, 
    I have a requirement to hide flter in standard Search Master Agreements top level query.  See below screen shot
    I have an idea how to delete filter in query but when i have added that query to top level navigation i don't have any idea.
    So i want to hide Business Unit & Region filter in Search Master Agreement query when it is in top level navigation.
    If anyone have idea please share with me how to hide.
    Thanks,
    Lava

    Hi Lava,
    It is not a filter but this a Standard field which is coming from the Master Agreement.
    So, you cannot hide or even delete any field.
    But if it is a custom field you can hide it by inactivating the respective field in Extension Defination.
    Please let me know if you need any assistance.
    Thanks,
    Raj.

Maybe you are looking for