Query formulation help

hi guys, basically I need to formulate a query which will give me the records in which the primary key appears the most on the table.
IE
AOI EID CID PRICES DATES
o10 e02 c11 330000 15-JUN-08
o17 e03 c13 500000 21-JUL-08
o18 e06 c16 515000 13-AUG-08
o22 e12 c15 395000 31-AUG-08
o13 e05 c14 90000 09-SEP-08
o15 e02 c17 95000 21-SEP-08
o20 e07 c13 500000 01-OCT-08
o16 e11 c15 100000 31-OCT-08
o19 e09 c16 250000 07-NOV-08
o22 e11 c17 420000 25-NOV-08
o21 e08 c13 420000 28-Aug-08
therefore if I wanted to formulate the query based on which EID has the most instances in the table, it would give me e02 and e11.
I'm not sure if im no the right track but I have been fooling around with the COUNT aggregate operator but to no avail. IE...
SELECT M.eid FROM MakesD3 M GROUP BY M.EID HAVING COUNT(*) >...
Thanks in advance for the help

This?
select EID from (select EID,row_number() over (partition by EID order by EID) rn from MakeD3 order by rn desc)
  where rn = (select max(count(*)) from MakeD3 group by EID)or
select EID from (select EID,count(*) rn from MakeD3 group by EID order by rn desc)
where rn = (select max(count(*)) from MakeD3 group by EID);or
select EID from MakeD3
group by MakeD3
having count(*) = (select max(count(*)) from MakeD3 group by EID);Regards,
Prazy
Edited by: Prazy on Mar 15, 2010 9:42 AM

Similar Messages

  • Basic functions (high) in query formula for highest # of days past due

    Hi All,
    I hope you can help.  I am trying to create a formula in a query for FIAR Line Item Cube (0fiar_c03).  I would like to calculate the hightest number of days past due for open line items.  There is an operator 'high' in basic functions within the query formula.  Is it possible to use this?
    Regards,
    Cheryl Adamonis

    There is a workaround usind conditions.That is you can try to filter the top 10 % or top 10 after calculating the no of days past.However this way you will not be displaying complete dataset

  • How to improve the performance of the attached query, Please help

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description                    Object_owner          Object_name     Cost     Cardinality     Bytes     
    SELECT STATEMENT, GOAL = ALL_ROWS                              14     1     13
    SORT AGGREGATE                                                  1     13
    VIEW                         GEMINI_REPORTING               14     1     13
    HASH GROUP BY                                        14     1     103
    NESTED LOOPS                                        13     1     103
    HASH JOIN                                             12     1     85
    TABLE ACCESS BY INDEX ROWID     GEMINI_REPORTING     RCAMSIT          2     4     100
    NESTED LOOPS                                        9     5     325
    HASH JOIN                                        7     1     40
    SORT UNIQUE                                        2     1     18
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          SITE          2     1     18
    INDEX RANGE SCAN          GEMINI_PRIMARY          SITE_I0          1     1     
    TABLE ACCESS FULL          GEMINI_PRIMARY          SITE          3     27     594
    INDEX RANGE SCAN          GEMINI_REPORTING     RCAMSIT_I     1     1     5     
    TABLE ACCESS FULL     GEMINI_PRIMARY     CAMPAIGN                    3     127     2540
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          CAMBILLING     1     1     18
    INDEX UNIQUE SCAN     GEMINI_PRIMARY     CAMBILLING_U1                    0     1

    Hello,
    This has really nothing to do with the Oracle Forms product.
    Please, send the SQL or/and PL/SQL questions in the corresponding forums.
    Francois

  • Query formulas

    Hi All
    Can anyone please give me a list of query formulas e.g. pulling current date to paste into delivery date then add one day to display tomorrows date.
    Thanks

    Hi Dear,
    Please follow the following steps
    1) save this query in the Qry manager via Modules>Reports>Qry Wizard.
    then select any table>Next>select any row>next>next-->Finish then click on middle Pencil to edit the query..Paste the following qry..
    SELECT getdate() + 1
    then save this qry under any category.
    2) Apply the Formatted search by the saved query.
    Hope this wil hlp you...
    Warm Regards,
    Mahendra

  • BEX query formula

    HI,
        We want to write below formula in bex query, Kindly guide me, for inital(no value) i dont know what i have to use in query formula.
    if(temp = inital)
    elseif(temp>0)
    Thanks

    We can't check for SPACE, NULL, INITIAL in bex.... And the IF statement you can include keyfigure only.
    If you want to check for characteristics, then you have to go for Virtual characteristics.
    Search in the forum, you will get lot of thread on Virtual Characteristics.
    --- Thanks...

  • Cluster bar chart- sql query please help-

    Hi,
    I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
    Here is my table
    city     region      issue     value
    c1     north     i1     y
    c1     north     i2     y
    c2     north     i1     n
    c2     north     i2     y
    c3     south     i1     y
    c3     south     i2     n
    c4     east     i1     n
    c4     east     i2     n
    The bar chart will have 3 series, north south and east.
    And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
    How can I get something like this from the above table-
    region     issue     count(yes)
    north     i1     1
    north     i2     2
    south     i1     1
    south     i2     0
    east     i1     0
    east     i2     0
    thanks

    WITH table1 AS
    (SELECT 1435177 qte_id, 2 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no
    FROM dual
    table2 AS
    SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
    FROM dual
    SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
    FROM
    (SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
    FROM table1 t1, table2 t2
    WHERE t2.qte_id = t1.qte_id (+)
    AND t2.seq_no = t1.seq_no(+)
    ORDER BY 1,2
    WHERE t1_seq_no IS NOT NULL
    ORDER BY 1,2
    QTE_ID T2_SEQ_NO DIFF
    1435177 2 0
    1435177 5 0
    1435177 7 0
    1435177 8 0
    1435177 12 0
    1435177 14 0

  • Help: How to write a query formula?

    Problem. There are 4 tables of a database of a store:
    Table 1: Tarifs
    Columns: Tarif_number, Price
    Primary key: Tarif_number
    Table 2: Products
    Columns: Product_number, Product_name, Quantity;
    Primary key: Product_number
    Data: Tarif 1 - 100%, Tarif 2 - 75 %, Tarif 3 - 50 %, Tarif 4 - 25 % (discounts)
    Table 3: Customers
    Columns: Customer_Number, Customer_Name, Address, Phone;
    Primary Key: Client_Number
    Table 4: Sales
    Columns: Date, Product_Number, Tarif_Number, Quantity_Sold, Customer_Name
    Primary key: Date, Product_Number, Customer_Number, Tarif_Number
    The problem is to write SQL PLUS queries, which would bring the following results:
    i. Data off all customers (name, address, phone), who within the period from 3/4/2009 to 4/4/2009 purchased products containing the string "abc" in its name. The data should be arranged alphabetically by product name. The report should have a footnote including name of its author.
    ii which product was purchased the most frequently and the total purchase value. The footnote should include the title and the date of the printout.
    iii Catalogue product number, product name, quantity on store, quantity sold for any product in the database. The product name should be introduced from keyboard in order to make possible to enter this or similar query later.

    Queries not tested*
    I) SELECT cs.customer_name, cs.address, cs.phone
    FROM customers cs, sales sl, products prd
    WHERE cs.customer_number = sl.customer_number
    AND prd.product_number = sl.product_number
    AND sl.DATE BETWEEN TO_DATE ('3/4/2009', 'DD/MM/YYYY')
    AND TO_DATE ('4/4/2009', 'DD/MM/YYYY')
    AND LOWER (prd.product_name) LIKE '%abc%'
    II) SELECT prd.product_name, SUM (sl.quantity_sold * tf.price)
    FROM sales sl, product prd, tarifs tf
    WHERE sl.product_number = prd.product_number
    AND tf.tarif_number = sl.tarif_number
    GROUP BY sl.product_number
    HAVING COUNT (1) = (SELECT MAX (COUNT (1))
    FROM sales sl1
    GROUP BY sl1.product_number)
    III) SELECT prd.product_name, prd.quantity, SUM (sl.quantity_sold)
    FROM sales sl, product prd, tarifs tf
    WHERE sl.product_number = prd.product_number
    AND tf.tarif_number = sl.tarif_number
    GROUP BY sl.product_number

  • Problem with combination of two working query formulas

    Hey guys,
    I have a problem in building a formula correctly with the BEx formula logic. I am sure, you can help me with this.
    Right now I have four columns in my query. The first column (Actual) displays actual amounts either in local (10) or reporting (25) currency type depending on the optional selection either in the variable screen or in the free characteristics filter. The second column (Actual with Budget exch. rate) always shows the actual amounts with the budget exchange rate of the reporting currency. The third column (Budget) is build in the same way as the first column, but shows budget amount data. In the fourth column (Variance) the variance between budget and actual data should be calculated, but here lies the problem:
    The formula should differentiate the chosen columns for the calculation depending on what currency type is selected either from the optional variable selection before the query is executed or from the free characteristics filter. So if I select currency type 10 it should calculate the variance by subtracting the budget column from the first column, but if I select currency type 25 it should subtract the budget columng from the second column.
    I have implemented a formula which works already, but not for both selection possibilities (variable screen or free characteristics filter). Either the formula works when I input a currency type in the variable selection screen or when I select a filter value in the free characteristics filter. However, I need to combine both formulas in one working formula so that the user can choose if he wants to filter the currency already in the variable screen in the beginning or in the filter after query execution. Here are the two formulas which I need to get combined into one formula:
    Used Variables:
    VScreen_Selection --> value from the key of the optional Currency Type Variable from the Variable Selection Screen
    Filter_Selection: --> value from the key of the InfoObject Currency Type
    Formula for Variable Screen Selection:
    (VScreen_Selection == 10) * (Budget - Actual) + (VScreen_Selection == 25) * (Budget - Actual with Budget exch. rate)
    Formula for Free Characteristics Filter Selection:
    (Filter_Selection == 10) * (Budget - Actual) + (Filter_Selection == 25) * (Budget - Actual with Budget exch. rate)
    Can you help me to combine both Formulas? I can't believe that this is too difficult. Many Thanks in advance.
    Best Greets,
    Norbert

    Hello.
    Did you try this:
    Formula 1: Hidden
    (VScreen_Selection == 10) * (Budget - Actual) + (VScreen_Selection == 25) * (Budget - Actual with Budget exch. rate)
    Formula 2: Hidden
    (Filter_Selection == 10) * (Budget - Actual) + (Filter_Selection == 25) * (Budget - Actual with Budget exch. rate)
    Formula 3:
    (Filter_Selection <> 10) * (Filter_Selection <> 25) *Formula 1 +
    (VScreen_Selection <> 10) * (VScreen_Selection <> 25)*Formula 2

  • MDX formula help

    The formula below works just fine but I want to use a UDA driven member in Member Range and need help.
    IIF(
    Count(
    Intersect(
    {MemberRange( [Jan],[Apr] )},
    {[Time].CurrentMember}
    ) = 1, [Actual], [Forecast])
    I tried with
    IIF(
    Count(
    Intersect(
    {MemberRange( [Jan],UDA([Period],"CurrMonth") )},
    {[Time].CurrentMember}
    ) = 1, [Actual], [Forecast])
    but I get an error Error(1260052) - Syntax error in input MDX query on line 4 at token ')' CalcMbr
    not sure why is this not working - I think UDA() can result in a set but member range is expecting a member only??
    Please suggest any ideas to correct the code.

    also tried with {[Jan]:UDA([Period],"CurrMonth")}
    instead of {MemberRange( [Jan],UDA([Period],"CurrMonth") )} - but no luck
    Any suggestions?

  • OBIEE rpd formula help

    Hi All
    My problem is mainly relating to the usage of operators and functions in the OBIEE repository...
    I need to extract the file name from a given path... (this is basically for Usage Tracking purposes)
    The path can be of 4 types:
    1) /users/[email protected]/Charts Reports/Report\/test.) -- file Report\/test.
    2) /shared/project/Reports \/ Charts/test \/ Report -- file test \/ Report
    3) /shared/project/Reports \/ Charts/test Report -- file test Report
    4) /shared/project/Reports/Report 1 -- file Report 1
    The '\/' that you see happens, when you save a report/folder in Answers with a '/' in the name (it converts it to '\/' supposedly).
    I am not able to write a formula for a logical column that can extract the file name given these 4 types of input paths.
    I have a written a SQl query that does all this perfectly fine but am having a tough time converting this to the OBIEE formula. So I guess
    I'll have to start off separately on the rpd formula.
    I tried the following formula but it does not work for type 1) and 2) ... It works for types 3 and 4. Though I dont find anything wrong with
    this formula, I think the CASE operator might be a problem.
    CASE WHEN LOCATE ('\/',:PATH) > 0
    THEN CASE WHEN LOCATE ( '\/',SUBSTRING(:PATH FROM LOCATE ('/', SUBSTRING (:PATH FROM 1 FOR LOCATE ('\/',:PATH,-1) ) ,-1 ) + 1 ) ) > 0
    THEN SUBSTRING (:PATH FROM LOCATE ( '/',:PATH,-1)+1 )
    ELSE SUBSTRING(:PATH FROM LOCATE ('/', SUBSTRING (:PATH FROM 1 FOR LOCATE ('\/',:PATH,-1) ) ,-1 ) + 1 )
    END
    ELSE
    SUBSTRING(:PATH FROM LOCATE ( '/',:PATH,-1) +1 )
    END
    Can someone help me write a better formula to perform this function
    Thanks a lot

    Hi All
    If this helps... When I said it does not work for the input types 1 and 2 (above post), this is the result that I get in Answers when I use my formula...
    Input 1) /users/[email protected]/Charts Reports/Report\/test.) Result: test.) Expected Result: Report\/test.)
    Input 2) /shared/project/Reports \/ Charts/test \/ Report Result: Report Expected Result: test \/ Report
    Thanks a lot...

  • Query Design help

    Hello Experts,
    I have a requirement, based on CHAR values I need to have an extra field which will have fixed values.
    Like if CHAR values is in the range of 100 - 199 new field value should be AA
    200 - 299 BB etc..
    example
    CHAR    -
    New(CHAR/KF)
    100   -
                   AA
    200   -
                   BB
    300   -
                  CC
    150   -
                  AA
    250   -
                 BB
    350  -
                  CC
    I would like to know how it is possible at the query design (Bex), I know it can possible at the Cube design,,,, but want to understand is there a way to get this done through RKF, CKF, etc....
    Thanks a lot in advance
    VJ

    Vijay
    If you can have numbers instead of AA / BB /CC then it can be accomplished using a formula ...
    You can have a simple IF statement for the same and accomplish the same at query level
    ((char>100)AND(char<199))*1 - this would return a value of 1 if CHAr is >100 and CHAR <199
    accordingly you can have numbers for AA , BB and CC...
    This is assuming that CHAR is a number... otherwise create a formula variable with replacement path for CHAR and use the same in the formula..
    Arun
    Hope it helps...
    Message was edited by:
            Arun Varadarajan

  • BEx Query Formula Descriptions -- Conditional Formula

    My question is in regards to the description that is returned from a formula within a structure.  The data I'm expecting is based on (for example) "fiscal year."  I have a text variable setup that returns the result of the "fiscal year" to be displayed as the column description.
    However if no data is returned for the current fiscal year, I then want to display the data for the previous fiscal year.
    I have a formula setup that uses a conditional statement.  It is setup as described below:
    <b>Formula Description</b>
    --  If data is returned based on fiscal year "2008" then use that data.
    --  Else use the data based on fiscal year "2007"
    <b>Issue</b>
    -- I use a text variable that is based on 0FISCYEAR called <b>0T_FYEAR</b>
    -- When the query is run, the data returned is correct --> (2007 data if there is no 2008 data)
    -- The text variable is also used as the formula "description" which is set to "0T_FYEAR" so if there was 2008 data, the text variable would say "2008" and if not it would say "2007."
    The problem resides in the text variable which is used as the formula description.  It is displaying the technical name of the text variable (&0T_FYEAR&) instead of "2008" or "2007."
    Has anyone else had this occur?  I would expect that if the data coming back is correctly based on 2008 or 2007, then the text variable used for the formula description would also be set to "2007" or "2008" based on my formula condition.
    Any help would be greatly appreciated and of course points will be awarded!
    Kevin

    Thanks for the quick response Pallavi...
    That logic seems completely backwards to me...is there a reason BEx is trying to populate the text variable values BEFORE knowing what data is actually being returned? 
    Also, my next obvious question:  Is there a way to get these variables populated with the correct value?  Can I force it to populate AFTER the formula has been executed so BEx knows which value to assign?
    What i'm trying to do is have a Year-Over-Year (last 3 years) comparison for the past 3 fiscal quarters.  So I would compare the current quarter numbers (Qtr 1) YoY Q1/2008, Q1/2007, Q1/2006 with the previous quarter...but the previous quarter is Q4 of 2007 (not 2008).  So I cant do the same 2008, 2007, 2006 comparison.  I was hoping to move the years back one for a 2007, 2006, 2005 comparison --> Thus the need for the conditional statement. 
    I hope that helps explain.  Any insight at all would be greatly appreciated.
    Kevin
    Message was edited by:
            Kevin Susko

  • Query Formula with boolean return values

    Hi,
    In my query, I have a  formula column which returns a boolean value 0 or 1. I need to add these values, but I cannot add them as boolean.  Is there a way that I could convert the boolean values to number/integer so I can add them?
    Thanks in advance
    Best Regards,
    Rose

    Hi Rose,
    please change 'Calaculate Result as' in properties of affected formula to 'Summation'.
    If this sould not help put formula in brackets and multiply by value 1 or create a new formula like
    (yourformula = 0 + yourformula = 1) * 1
    this should provide an integer.
    Regards
    Joe

  • Cell definitions with Query formulas

    I have a query with cell definitions used.
    My problem is when I use a formula in one of the original query columns, it ignores the cell definitions and considers the orignal columns definitons.
    My understanding is that cell definitions overwrite the original query column defintion by default.
    The only way I can think of it, is that I should do all my formulas in the cell definitoins editr for all affected cells (one by one).
    Anyone had a similar problem.
    your help is appreciated.
    Thanx in advance

    I'm not sure if i understood correctly, you have the a formula defined in query columns let's suppose ab, and for the same formula intersection in the cell defnition you have another formula bc.
    But the query is returnign the result of a*b ? Am i correct in understanding ? If this is right, then why do you have calculations in both the places....

  • Query question/help

    hi,
    i need some help in trying to create a query to show the table_name, mb_used and degree of parallelism.
    this is what i currently have..
    SELECT a.segment_name, sum(ROUND((BYTEs/1048576*100)/100)) "MB size"
    FROM dba_Segments a
    WHERE a.owner= ??
    and segment_type='TABLE'
    group by segment_name
    order by segment_name;
    select table_name, degree
    from dba_Tables
    where owner='ADW_UTL'
    and tablespace_name is not null
    order by table_name;
    how can i combined the two?
    thanks in advance..

    Hi,
    SELECT a.segment_name, sum(ROUND((BYTEs/1048576*100)/100)) "MB size", b.degree
    FROM dba_Segments a, dba_tables b
    WHERE a.owner= 'xxx'
    and a.owner = b.owner
    and segment_type='TABLE'
    group by segment_name, degree
    order by segment_name;
    Cheers

Maybe you are looking for