5- 6 Measure Objects in A Single Query

Hi Techies,
I want to see the consolidated value of the measure object's of my universe,
when I place my measure objects(6) in the single query, with a conditional object and wen I run the query I am seeing an error message as no data to retrieve.
and If I take one measure object in each query I am able to see some data, is there any reason behind this ..
can't I proceed with single query with all my measure objects in the same query rather than many data providers for each measure object.
Please suggest me on this
Thanks in advance .............

All the measure objects are coming from single table only,
and the conditional object means we have written some condition at universe level and these objects refer to another table and there is a necessary join between these two tables...

Similar Messages

  • Drill function implemented on Measure object column in the webi report

    Post Author: madan kumar
    CA Forum: WebIntelligence Reporting
    Hi,
    I have a small issue in my project.(Maintenance Project)I created a measure object in the fact table of the existing universe and saved and exported to the repository. (Say Measure object is D where D = A-(B+C))I inserted the same object as a column between two measure objects columns of a existing WebI report.
    The report has two hierarchies involved  - each hierarchy has dimension objects involved.I have checked with the hierarchies to make sure that measure object is not involved.The scope of analysis is None for the query.Version is BO XI R2.
    The issue is the Drill function is implemented on that particular new column.The drill function should be applicable only to the two dimension objects involved in the report.But this measure object column is also getting drilled once the Drill option is selected.I had to remove the drill optiion from the Measure object column.
    Can anyone help me on this issue...
    Thanks in advance...
    Madan Kumar

    Sushil
    Thanks for your reply. I did the date diff on the columns. It does not  break into 3 different groups. I am using a function called previous on the date column. So the report is like this
        DATE                           Pervious (DATE)                 Date - Pervious(DATE)
    01-01-2008 01:06              Null                                
    01-01-2008 01:12              01-01-2008 01:06               :06
    01-01-2008 01:18              01-01-2008 01:12               :06
    01-01-2008 01:24              01-01-2008 01:18               :06
    01-01-2008 01:30             01-01-2008 01:24              :06
    01-01-2008 01:36             01-01-2008 01:30               :06
    Basically we are breaking on the Date - Previous ( Date) column which does not work. I am not sure if there is a way to break this. I even tried it in Crystal REports XI and it does not work their either. Any help with this issue with be greatly appriciated.
    Edited by: Srinivasa Prabu on Aug 4, 2008 2:55 PM
    Edited by: Srinivasa Prabu on Aug 4, 2008 2:56 PM

  • How to measure the performance of sql query?

    Hi Experts,
    How to measure the performance, efficiency and cpu cost of a sql query?
    What are all the measures available for an sql query?
    How to identify i am writing optimal query?
    I am using Oracle 9i...
    It ll be useful for me to write efficient query....
    Thanks & Regards

    psram wrote:
    Hi Experts,
    How to measure the performance, efficiency and cpu cost of a sql query?
    What are all the measures available for an sql query?
    How to identify i am writing optimal query?
    I am using Oracle 9i... You might want to start with a feature of SQL*Plus: The AUTOTRACE (TRACEONLY) option which executes your statement, fetches all records (if there is something to fetch) and shows you some basic statistics information, which include the number of logical I/Os performed, number of sorts etc.
    This gives you an indication of the effectiveness of your statement, so that can check how many logical I/Os (and physical reads) had to be performed.
    Note however that there are more things to consider, as you've already mentioned: The CPU bit is not included in these statistics, and the work performed by SQL workareas (e.g. by hash joins) is also credited only very limited (number of sorts), but e.g. it doesn't cover any writes to temporary segments due to sort or hash operations spilling to disk etc.
    You can use the following approach to get a deeper understanding of the operations performed by each row source:
    alter session set statistics_level=all;
    alter session set timed_statistics = true;
    select /* findme */ ... <your query here>
    SELECT
             SUBSTR(LPAD(' ',DEPTH - 1)||OPERATION||' '||OBJECT_NAME,1,40) OPERATION,
             OBJECT_NAME,
             CARDINALITY,
             LAST_OUTPUT_ROWS,
             LAST_CR_BUFFER_GETS,
             LAST_DISK_READS,
             LAST_DISK_WRITES,
    FROM     V$SQL_PLAN_STATISTICS_ALL P,
             (SELECT *
              FROM   (SELECT   *
                      FROM     V$SQL
                      WHERE    SQL_TEXT LIKE '%findme%'
                               AND SQL_TEXT NOT LIKE '%V$SQL%'
                               AND PARSING_USER_ID = SYS_CONTEXT('USERENV','CURRENT_USERID')
                      ORDER BY LAST_LOAD_TIME DESC)
              WHERE  ROWNUM < 2) S
    WHERE    S.HASH_VALUE = P.HASH_VALUE
             AND S.CHILD_NUMBER = P.CHILD_NUMBER
    ORDER BY ID
    /Check the V$SQL_PLAN_STATISTICS_ALL view for more statistics available. In 10g there is a convenient function DBMS_XPLAN.DISPLAY_CURSOR which can show this information with a single call, but in 9i you need to do it yourself.
    Note that "statistics_level=all" adds a significant overhead to the processing, so use with care and only when required:
    http://jonathanlewis.wordpress.com/2007/11/25/gather_plan_statistics/
    http://jonathanlewis.wordpress.com/2007/04/26/heisenberg/
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • How to calculate the area of a large number of polygons in a single query

    Hi forum
    Is it possible to calculate the area of a large number of polygons in a single query using a combination of SDO_AGGR_UNION and SDO_AREA? So far, I have tried doing something similar to this:
    select sdo_geom.sdo_area((
    select sdo_aggr_union (   sdoaggrtype(mg.geoloc, 0.005))
    from mapv_gravsted_00182 mg 
    where mg.dblink = 521 or mg.dblink = 94 or mg.dblink = 38 <many many more....>),
    0.0005) calc_area from dualThe table MAPV_GRAVSTED_00182 contains 2 fields - geoloc (SDO_GEOMETRY) and dblink (Id field) needed for querying specific polygons.
    As far as I can see, I need to first somehow get a single SDO_GEOMETRY object and use this as input for the SDO_AREA function. But I'm not 100% sure, that I'm doing this the right way. This query is very inefficient, and sometimes fails with strange errors like "No more data to read from socket" when executed from SQL Developer. I even tried with the latest JDBC driver from Oracle without much difference.
    Would a better approach be to write some kind of stored procedure, that adds up all the single geometries by adding each call to SDO_AREA on each single geometry object - or what is the best approach?
    Any advice would be appreciated.
    Thanks in advance,
    Jacob

    Hi
    I am now trying to update all my spatial table with SRID's. To do this, I try to drop the spatial index first to recreate it after the update. But for a lot of tables I can't drop the spatial index. Whenever I try to DROP INDEX <spatial index name>, I get this error - anyone know what this means?
    Thanks,
    Jacob
    Error starting at line 2 in command:
    drop index BSSYS.STIER_00182_SX
    Error report:
    SQL Error: ORA-29856: error occurred in the execution of ODCIINDEXDROP routine
    ORA-13249: Error in Spatial index: cannot drop sequence BSSYS.MDRS_1424B$
    ORA-13249: Stmt-Execute Failure: DROP SEQUENCE BSSYS.MDRS_1424B$
    ORA-29400: data cartridge error
    ORA-02289: sequence does not exist
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 27
    29856. 00000 - "error occurred in the execution of ODCIINDEXDROP routine"
    *Cause:    Failed to successfully execute the ODCIIndexDrop routine.
    *Action:   Check to see if the routine has been coded correctly.
    Edit - just found the answer for this in MetaLink note 241003.1. Apparently there is some internal problem when dropping spatial indexes, some objects gets dropped that shouldn't be. Solution is to manually create the sequence it complains it can't drop, then it works... Weird error.

  • 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

  • Group by function in a measure object

    Hi All,
        I am trying to create a measure in universe which is the sum of ticket amount group by country. like,
    sum(Payments.Ticket_Amount) group by country name. When i place this measure in a report group footer it should display the sum to that particular group. But it is not working.
    Could anybody help me how to write a group by function to create a measure.
    Thanks,
    swati.

    Hi swati.
    You don't need to write the GROUP BY statement at the universe level.
    The universe knows that aggregate functions require group by statements and will group the aggregate measure objects by whatever dimension objects are included in the query. If you have a measure object that is not based on an aggregate but has a projection of Sum, it will only be aggregated at the report level once the data has been returned by the query.
    Measure: sum(sales_fact.value)
    Measure: sales_fact.price
    Dimension: country_dim.country
    This would generate SQL along the lines of:
    SELECT sales_fact.price, country_dim.country, sum(sales_fact.value)
    FROM sales_fact, country_dim
    WHERE sales_fact.country_key = country_dim.country_key
    GROUP BY sales_fact.price, country_dim.country
    Hope that clears it up for you.
    Regards,
    Mark

  • Need different rows from single query based on condition

    Hi,
    I have a table with 100 rows that holds employees and their roles.
    I need to write a SQL(not a PL/SQL block) as below
    1. When employee with role 'VP' logs in, the query should return all the 100 rows.
    2. When employee with role 'MGR' logs in, the query should return only those rows whose MGR is the logged in employee.
    3. When employee with role 'SALE_EXEC' logs in, it should return single rows corresponding to this SALE_EXEC.
    My requirement here is to get these outputs from a single query.
    Can anyone please help me with this.
    Thanks,
    Vivek.

    use vpd
    New Policy Groups
    When adding the policy to a table, view, or synonym, you can use the DBMS_RLS.ADD_GROUPED_POLICY interface to specify the group to which the policy belongs. To specify which policies will be effective, you add a driving context using the DBMS_RLS.ADD_POLICY_CONTEXT interface. If the driving context returns an unknown policy group, then an error is returned.
    If the driving context is not defined, then all policies are executed. Likewise, if the driving context is NULL, then policies from all policy groups are enforced. In this way, an application accessing the data cannot bypass the security setup module (which sets up application context) to avoid any applicable policies.
    You can apply multiple driving contexts to the same table, view, or synonym, and each of them will be processed individually. In this way, you can configure multiple active sets of policies to be enforced.
    Consider, for example, a hosting company that hosts Benefits and Financial applications, which share some database objects. Both applications are striped for hosting using a SUBSCRIBER policy in the SYS_DEFAULT policy group. Data access is partitioned first by subscriber ID, then by whether the user is accessing the Benefits or Financial applications (determined by a driving context). Suppose that Company A, which uses the hosting services, wants to apply a custom policy which relates only to its own data access. You could add an additional driving context (such as COMPANY A SPECIAL) to ensure that the additional, special policy group is applied for data access for Company A only. You would not apply this under the SUBSCRIBER policy, because the policy relates only to Company A, and it is more efficient to segregate the basic hosting policy from other policies.
    How to Implement Policy Groups
    To create policy groups, the administrator must do two things:
    Set up a driving context to identify the effective policy group.
    Add policies to policy groups as required.
    The following example shows how to perform these tasks.
    Note:
    You need to set up the following data structures for the examples in this section to work:
    DROP USER finance CASCADE;
    CREATE USER finance IDENTIFIED BY welcome2;
    GRANT RESOURCE TO apps;
    DROP TABLE apps.benefit;
    CREATE TABLE apps.benefit (c NUMBER);
    Step 1: Set Up a Driving Context
    Begin by creating a namespace for the driving context. For example:
    CREATE CONTEXT appsctx USING apps.apps_security_init;
    Create the package that administers the driving context. For example:
    CREATE OR REPLACE PACKAGE apps.apps_security_init IS
    PROCEDURE setctx (policy_group VARCHAR2);
    END;
    CREATE OR REPLACE PACKAGE BODY apps.apps_security_init AS
    PROCEDURE setctx ( policy_group varchar2 ) IS
    BEGIN
    REM Do some checking to determine the current application.
    REM You can check the proxy if using the proxy authentication feature.
    REM Then set the context to indicate the current application.
    DBMS_SESSION.SET_CONTEXT('APPSCTX','ACTIVE_APPS', policy_group);
    END;
    END;
    Define the driving context for the table APPS.BENEFIT.
    BEGIN
    DBMS_RLS.ADD_POLICY_CONTEXT('apps','benefit','APPSCTX','ACTIVE_APPS');
    END;
    Step 2: Add a Policy to the Default Policy Group.
    Create a security function to return a predicate to divide the data by company.
    CREATE OR REPLACE FUNCTION by_company (sch varchar2, tab varchar2)
    RETURN VARCHAR2 AS
    BEGIN
    RETURN 'COMPANY = SYS_CONTEXT(''ID'',''MY_COMPANY'')';
    END;
    Because policies in SYS_DEFAULT are always executed (except for SYS, or users with the EXEMPT ACCESS POLICY system privilege), this security policy (named SECURITY_BY_COMPANY), will always be enforced regardless of the application running. This achieves the universal security requirement on the table: namely, that each company should see its own data regardless of the application that is running. The function APPS.APPS_SECURITY_INIT.BY_COMPANY returns the predicate to make sure that users can only see data related to their own company:
    BEGIN
    DBMS_RLS.ADD_GROUPED_POLICY('apps','benefit','SYS_DEFAULT',
    'security_by_company',
    'apps','by_company');
    END;
    Step 3: Add a Policy to the HR Policy Group
    First, create the HR group:
    CREATE OR REPLACE FUNCTION hr.security_policy
    RETURN VARCHAR2
    AS
    BEGIN
    RETURN 'SYS_CONTEXT(''ID'',''TITLE'') = ''MANAGER'' ';
    END;
    The following creates the policy group and adds a policy named HR_SECURITY to the HR policy group. The function HR.SECURITY_POLICY returns the predicate to enforce security on the APPS.BENEFIT table:
    BEGIN
    DBMS_RLS.CREATE_POLICY_GROUP('apps','benefit','HR');
    DBMS_RLS.ADD_GROUPED_POLICY('apps','benefit','HR',
    'hr_security','hr','security_policy');
    END;
    Step 4: Add a Policy to the FINANCE Policy Group
    Create the FINANCE policy:
    CREATE OR REPLACE FUNCTION finance.security_policy
    RETURN VARCHAR2
    AS
    BEGIN
    RETURN ('SYS_CONTEXT(''ID'',''DEPT'') = ''FINANCE'' ');
    END;
    Create a policy group named FINANCE and add the FINANCE policy to the FINANCE group:
    BEGIN
    DBMS_RLS.CREATE_POLICY_GROUP('apps','benefit','FINANCE');
    DBMS_RLS.ADD_GROUPED_POLICY('apps','benefit','FINANCE',
    'finance_security','finance', 'security_policy');
    END;
    As a result, when the database is accessed, the application initializes the driving context after authentication. For example, with the HR application:
    execute apps.security_init.setctx('HR');
    Validating the Application Used to Connect to the Database
    The package implementing the driving context must correctly validate the application that is being used to connect to the database. Although the database always checks the call stack to ensure that the package implementing the driving context sets context attributes, inadequate validation can still occur within the package.
    For example, in applications where database users or enterprise users are known to the database, the user needs the EXECUTE privilege on the package that sets the driving context. Consider a user who knows that:
    The BENEFITS application allows more liberal access than the HR application
    The setctx procedure (which sets the correct policy group within the driving context) does not perform any validation to determine which application is actually connecting. That is, the procedure does not check either the IP address of the incoming connection (for a three-tier system) or the proxy_user attribute of the user session.
    Such a user could pass to the driving context package an argument setting the context to the more liberal BENEFITS policy group, and then access the HR application instead. Because the setctx does no further validation of the application, this user bypasses the normally more restrictive HR security policy.
    By contrast, if you implement proxy authentication with VPD, then you can determine the identity of the middle tier (and the application) that is actually connecting to the database on behalf of a user. In this way, the correct policy will be applied for each application to mediate data access.
    For example, a developer using the proxy authentication feature could determine that the application (the middle tier) connecting to the database is HRAPPSERVER. The package that implements the driving context can thus verify whether the proxy_user in the user session is HRAPPSERVER. If so, then it can set the driving context to use the HR policy group. If proxy_user is not HRAPPSERVER, then it can disallow access.
    In this case, when the following query is executed
    SELECT * FROM APPS.BENEFIT;
    Oracle Database picks up policies from the default policy group (SYS_DEFAULT) and active namespace HR. The query is internally rewritten as follows:
    SELECT * FROM APPS.BENEFIT WHERE COMPANY = SYS_CONTEXT('ID','MY_COMPANY') and SYS_CONTEXT('ID','TITLE') = 'MANAGER';
    How to Add a Policy to a Table, View, or Synonym
    The DBMS_RLS package enables you to administer security policies by using its procedures for adding, enabling, refreshing, or dropping policies, policy groups, or application contexts. You need to specify the table, view, or synonym to which you are adding a policy, as well as the data pertinent to that policy, such as the policy name. Such data also includes names for the policy group and the function implementing the policy. You can also specify the types of statements the policy controls (SELECT, INSERT, UPDATE, DELETE, CREATE INDEX, or ALTER INDEX).
    for more you can refer to
    http://download-west.oracle.com/docs/cd/B19306_01/network.102/b14266/apdvcntx.htm

  • Updating multiple node in a single query

    Hi
    Shall I update multiple nodes (which satisfies the given condition) in a single query? From the prototype we suspect that all nodes in all document are not updated in the container.
    Version: BDB XML 2.4 - Fedora core 4 Linux - C++ language
    Query:
    replace value of node collection()/File[@Id="57565C01327A"]//Entry[@Class="Measurement" and @Id="0"]/Attribute[@Name="apDlBhUtil"]/@Value with 8'
    Result:
    XmlException occurred with msg 'Error: Sequence does not match type node() - the sequence contains more than one item [err:XUTY0008], <query>:1:1'
    We have tried running the query in both Lazy and Eager evaluation type. Please clarify that the issue is with the query/execution type or BDB XML doesn't support this feature?
    Thanks
    Santhosh

    Santhosh,
    Try:
    for $i in collection()/File[@Id="57565C01327A"]//Entry[@Class="Measurement" and @Id="0"]/Attribute[@Name="apDlBhUtil"]/@Value return replace value of node $i with 8'The problem with your original is that the argument for "replace value of" needs to be a single item, not a sequence.
    Regards,
    George

  • How to use multiple hierarchies for a single char in single query

    Hi,
    Is there any way that we can use multiple hierarchies for a single char in single query. I tried and it just allows me to select one hierarchy even if I use hierarchy variable.
    I have a requirement where user wants to see information related to a cost center with different cost center groups in different hierarchies (every year has different cost center group hierarchies).
    Suppose I want to see information related to a cost center from year 2001-2004.in these four year cost center may have been associated to different groups depending upon that year hierarchy. How can I do that?
    Thanks
    Jona

    Nope. Now way to do this.
    There is always just one hierarchy assigned to a characteristic. And even if the hierarchy was time dependent, it only reads it for one key date and not according to transaction data.
    Regards,
    Beat

  • Multiple databases in a single query

    I need to query multiple databases in a single query.
    e.g.
    Database d1 contains table t1 with column id
    Database d2 contains table t2 with column id
    I need a query like
    SELECT * FROM t1, t2 WHERE t1.id = t2.id;
    is this possible in jdbc? if yes can anyone help with some sample code?
    thanks,
    Ashish Saraf

    It is not possible using the JDBC API to query tables in two or more databases using a single query. The reason is that a JDBC Connection is made to a single data source.
    However, some databases support the idea of federations or linked tables. What you do is inside the database manager link or federate a table that is present in another DBMS. Then, pose a single JDBC query to the one DBMS which will have its own table and links to the external tables.
    Another approach is to use a special JDBC driver with a built-in integration engine that will perform a query across multiple databases. In effect, the system poses separate queries to the different databases and integrates and joins the data together for you automatically on the client-side. That is much easier than doing it yourself in code, but that is also possible for simple queries.
    As part of my research program, we have released a shareware version of the UnityJDBC driver that can query multiple databases using a single SQL query. For more information, see:
    http://www.unityjdbc.com
    http://www.cs.uiowa.edu/~rlawrenc/research/projects.html
    Sincerely,
    Dr. Ramon Lawrence
    Assistant Professor
    Department of Computer Science
    University of Iowa
    [email protected]

  • Populate Multiple Items bundled in a single query

    Hello,
    I am trying to create a report in which I have mulitple items that I want to populate. All of these use the same query but use different rows in the query to populate themselves. My question is:-
    Is there a way to bundle the item assignment into a single query and populate the items from there? I want to reduce the time it takes for me to display the report and just hit the database once instead.

    Hi there,
    when u say report, i think its a more of a page showing few items on a region whose values are populated from Database rather than a SQL report which will not have any items. Is that correct?
    yes, multiple items of a page can be assigned values at once.
    assume: P1_ITEM1,P1_ITEM2,P1_ITEM3,P1_ITEM4 are different items on a page, an "On-Load Before Header" PL/SQL process can be created to assign values to the items in this way:
    SELECT tab.col1,tab.col2,tab.col3,tab.col4 INTO :P1_ITEM1,:P1_ITEM2,:P1_ITEM3,:P1_ITEM4 FROM TABLE tab;
    Item "Source Used" should be of type: Only When Current Value in session state is null
    Source Type: PL/SQL Expression or function
    and Source Value or EXpression should be some thing like this :P1_ITEM1
    Hope this helps.
    Edited by: Chaitu_Apex on Mar 10, 2010 2:43 PM

  • How to make the query in one single query? No Union please....

    Hi,
    I have sets of around 18 queries which is finding counts in many scenarios. I wanted to have a single query for this. which diplays the result in a single row.Is there a way , I heared analytical functions are good options ,but I am new to Oracle . Please help me.
    select count(*) total_count from emp; --100
    select coun(*) MGR_count from emp where job='MGR'-- 10
    select count(*) dept_count from emp where deptno in(10 ,20)-- 75
    output..
    TOTAL_COUNT     MGR_COUNT      DEPT_COUNT
    100                                   10             75
    Thanks

    This:
    select count(*) total_Count
          ,count(decode(job,'MGR',1,null)) mgr_count
          ,count(case when deptno in (10,20) then
                   1
                 else
                   null
                 end
                ) dept_count
    from emp;
    untested

  • Multiple conditin on a single column in a single query

    i want to select data from the table using diff conditions on a single column
    for eg:
    i need emp details like whose having empno as 5-15,19-45,50-89 ..etc this how can i give a condition in a single query
    we can use in or between for 2 or 3 conditions but i have plenty off like this

    Hi,
    848525 wrote:
    i want to select data from the table using diff conditions on a single column
    for eg:
    i need emp details like whose having empno as 5-15,19-45,50-89 ..etc this how can i give a condition in a single query
    we can use in or between for 2 or 3 conditions but i have plenty off like thisYou can use OR for any number of conditions; it works the same for 4 or more.
    You could also put the ranges into a table (or a sub-query, as shown below) and join:
    WITH     empno_ranges     AS
         SELECT     3000 AS low_val, 5000 AS high_val  FROM dual  UNION ALL
         SELECT     7000,           7499               FROM dual  UNION ALL
         SELECT     7500,           7599               FROM dual  UNION ALL
         SELECT     7800,           7899               FROM dual
    SELECT       r.*
    ,       COUNT (e.empno)     AS emp_cnt
    FROM            empno_ranges     r
    LEFT OUTER JOIN     scott.emp     e  ON  e.empno  BETWEEN r.low_val
                                                 AND     r.high_val
    GROUP BY  r.low_val, r.high_val
    ORDER BY  r.low_val
    ;Output:
    LOW_VAL   HIGH_VAL    EMP_CNT
       3000       5000          0
       7000       7499          2
       7500       7599          2
       7800       7899          3

  • All selected 'n' consecutive rows in retrieved in a single query

    hello,
    I have table T with 50,000 rows
    create table T
    (student_id number,
    class_id number,
    quiz_id number,
    marks number)
    some sample rows like
    INSERT INTO T VALUES (1,1, 1, 50);
    INSERT INTO T VALUES (2,2, 2, 40);
    INSERT INTO T VALUES (3,1, 3, 34);
    INSERT INTO T VALUES (1,1, 4, 10);
    INSERT INTO T VALUES (1,1, 5, 30);
    INSERT INTO T VALUES (1,1, 6, ‘29);
    INSERT INTO T VALUES (3,2, 7, 34);
    INSERT INTO T VALUES (3,2, 8, 33);
    INSERT INTO T VALUES (3,2, 9, 56);
    INSERT INTO T VALUES (1,1, 7, 90);
    INSERT INTO T VALUES (2,2, 8, 0,);
    INSERT INTO T VALUES (1,1, 8, 80);
    INSERT INTO T VALUES (2,2, 8, 65);
    INSERT INTO T VALUES (1,1, 9, ‘34);
    INSERT INTO T VALUES (2,2, 9, 11);each student belongs to one class_id. each student participates in many quizes. each quiz has its unique id. each student can appear once in a quiz_id
    I am doing the below analysis and query:
    1. with below query I am finding which student_id had most marks in any 3 successive quizes (see the 3-1 part below) in the query..
    SELECT QUIZ_ID,
          STUDENT_ID,
    SUM (MARKS) OVER (PARTITION BY STUDENT_ID ORDER BY QUIZ_ID1
    RANGE BETWEEN CURRENT ROW AND (3-1) FOLLOWING) consecMARKS , MARKS   FROM
          (SELECT QUIZ_ID,
            STUDENT_ID,
            MARKS,
          ROW_NUMBER() OVER (PARTITION BY STUDENT_ID ORDER BY T.QUIZ_ID) QUIZ_ID1
          FROM T
          WHERE MARKS IS NOT NULL
          ORDER BY 1
        ORDER BY 3 DESC
    SQL> /
       QUIZ_ID STUDENT_ID CONSECMARKS
             7          1         170
             6          1         166
             8          1         129
             5          1         106
             8          3          89
             8          2          76
             3          3          68
             7          3          67
             8          2          65
             1          1          60
             9          3          56
       QUIZ_ID STUDENT_ID CONSECMARKS
             9          1          49
             2          2          40
             4          1          40
             9          2          11
    15 rows selected.With above query, I can play around and find for any 'n' number of consecutive quizes, like marks in 2 consecutives quizes, 3, 4 and so on but for each 'n' value I've to run a seperate query mentioning (2-1) or (3-1) or (4-1) and so on..
    since my table is big and there are about 400 quizes so what I want to find out is for each 'n' consecutive quiz (from 1 to 400) which student had most marks for each consecutie 'n' quiz. Like in 1 (consecutive) quiz which student had the highest marks and then 2 conseuctive quiz who had most marks and then in 3 consecutive quiz who had most marks and so on till 400 consecutive quiz who had most marks... rather than running query for each 'n' value seperately i want a single query that can give me a summary of most marks in each n consecutive quizes...
    my sample output is:
    Nth consecutive quiz     student_id    sum(marks)
    1                        1              90
    2                        1              170
    3                        1              246
    4
    100
    200
    300
    400                      ?              ?   Is this possible to get the above output from one single query? If there are two or more students with equal most marks for any 'n' conseutive quizes then both should come in the summary.
    Hope I have been able to put up my question clearly.
    regards
    Ramis

    Something like:
    SELECT  N,
            QUIZ_ID,
            STUDENT_ID,
            SUM(MARKS) OVER (PARTITION BY N,STUDENT_ID ORDER BY QUIZ_ID1 RANGE BETWEEN CURRENT ROW AND (N-1) FOLLOWING) consecMARKS,
            MARKS
      FROM  (SELECT  QUIZ_ID,
                     STUDENT_ID,
                     MARKS,
                     ROW_NUMBER() OVER (PARTITION BY STUDENT_ID ORDER BY T.QUIZ_ID) QUIZ_ID1
               FROM  T
               WHERE MARKS IS NOT NULL
             SELECT  LEVEL N
               FROM  DUAL
               CONNECT BY LEVEL <= (
                                    SELECT  COUNT(DISTINCT QUIZ_ID)
                                      FROM  T
        ORDER BY N,
                 consecMARKS DESC
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             1          7          1          90         90
             1          8          1          80         80
             1          8          2          65         65
             1          9          3          56         56
             1          1          1          50         50
             1          2          2          40         40
             1          9          1          34         34
             1          7          3          34         34
             1          3          3          34         34
             1          8          3          33         33
             1          5          1          30         30
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             1          6          1          29         29
             1          9          2          11         11
             1          4          1          10         10
             1          8          2           0          0
             2          7          1         170         90
             2          6          1         119         29
             2          8          1         114         80
             2          8          3          89         33
             2          8          2          76         65
             2          3          3          68         34
             2          7          3          67         34
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             2          8          2          65          0
             2          1          1          60         50
             2          5          1          59         30
             2          9          3          56         56
             2          2          2          40         40
             2          4          1          40         10
             2          9          1          34         34
             2          9          2          11         11
             3          7          1         204         90
             3          6          1         199         29
             3          5          1         149         30
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             3          7          3         123         34
             3          8          1         114         80
             3          2          2         105         40
             3          3          3         101         34
             3          1          1          90         50
             3          8          3          89         33
             3          8          2          76         65
             3          8          2          76          0
             3          4          1          69         10
             3          9          3          56         56
             3          9          1          34         34
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             3          9          2          11         11
             4          6          1         233         29
             4          5          1         229         30
             4          7          1         204         90
             4          4          1         159         10
             4          3          3         157         34
             4          7          3         123         34
             4          1          1         119         50
             4          2          2         116         40
             4          8          1         114         80
             4          8          3          89         33
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             4          8          2          76          0
             4          8          2          76         65
             4          9          3          56         56
             4          9          1          34         34
             4          9          2          11         11
             5          5          1         263         30
             5          4          1         239         10
             5          6          1         233         29
             5          1          1         209         50
             5          7          1         204         90
             5          3          3         157         34
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             5          7          3         123         34
             5          2          2         116         40
             5          8          1         114         80
             5          8          3          89         33
             5          8          2          76          0
             5          8          2          76         65
             5          9          3          56         56
             5          9          1          34         34
             5          9          2          11         11
             6          1          1         289         50
             6          4          1         273         10
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             6          5          1         263         30
             6          6          1         233         29
             6          7          1         204         90
             6          3          3         157         34
             6          7          3         123         34
             6          2          2         116         40
             6          8          1         114         80
             6          8          3          89         33
             6          8          2          76          0
             6          8          2          76         65
             6          9          3          56         56
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             6          9          1          34         34
             6          9          2          11         11
             7          1          1         323         50
             7          4          1         273         10
             7          5          1         263         30
             7          6          1         233         29
             7          7          1         204         90
             7          3          3         157         34
             7          7          3         123         34
             7          2          2         116         40
             7          8          1         114         80
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             7          8          3          89         33
             7          8          2          76          0
             7          8          2          76         65
             7          9          3          56         56
             7          9          1          34         34
             7          9          2          11         11
             8          1          1         323         50
             8          4          1         273         10
             8          5          1         263         30
             8          6          1         233         29
             8          7          1         204         90
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             8          3          3         157         34
             8          7          3         123         34
             8          2          2         116         40
             8          8          1         114         80
             8          8          3          89         33
             8          8          2          76          0
             8          8          2          76         65
             8          9          3          56         56
             8          9          1          34         34
             8          9          2          11         11
             9          1          1         323         50
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             9          4          1         273         10
             9          5          1         263         30
             9          6          1         233         29
             9          7          1         204         90
             9          3          3         157         34
             9          7          3         123         34
             9          2          2         116         40
             9          8          1         114         80
             9          8          3          89         33
             9          8          2          76          0
             9          8          2          76         65
             N    QUIZ_ID STUDENT_ID CONSECMARKS      MARKS
             9          9          3          56         56
             9          9          1          34         34
             9          9          2          11         11
    135 rows selected.
    SQL> SY.

  • Is it possible to combine 2 different reports in a single Query?

    Dear All,
    What am I working at?
    I produced a Query for Debtors Aged Analysis which mimics the Official SAP B1 8.8 Aging Report.
    It ages the outstanding invoices by Posting Date ( RefDate  in JDT1)
    I also made another Report which ages outstanding amounts by Document Date simply by replacing all RefDate by TaxDate
    They give different answers if Posting Date is different from Document Date, e.g a manual invoice dated 5 Jun 2011 is posted on 2 Jul 2011.
    What I want to do?
    My idea is to produce a SINGLE QUERY which will generate either Aging depending on settings:
        (a) A Debtors Aging by Posting Date
        (b) A Debtors Aging by Document Date
    I declare 2 variables:
    (a) @refdt  is [%1] and represents Posting Date (JDT1 RefDate)
    (b) @taxdt  is [%2] and represents Document Date (JDT1 TaxDate)
    When the Query is run, the foll dialog appears:
    Query - Selection Criteria
    Posting Date             Equal .......
    Document Date            Equal .......
    OK   Cancel
    We are expected to fill in only 1 date and leave the other blank, and Query will generate the required report .
    What is my problem?
    Query runs smoothly, but amounts in the Balance column does not get analyzed in the Age brackets: Current / 1 Mth Ago / etc
    I think I know where's the problem
    I am assuming (wrongly) that if we don't fill one date field, the query returns NULL for that variable. In fact, it appears to return GetDate().
    Help
    Can anybody help me put the correct commands so that all my balances are correctly analysed in the respective age buckets?
    Thanks
    Leon Lai
    Here's a simplified SQL:
    Tables  :
          JDT1   T0  = Journal Entry - Rows
          OCRD T1 = Business Partner
          OCPR T2 = Contact Person
          OJDT  T3  = Journal Entry - Header
          OINV   T4  = A/R Invoices - Header
          ORIN   T5  - A/R Credit Memo - Header
    declare @refdt date
    declare @taxdt date
    set @refdt
    /*Select 1 from jdt1 t where t.RefDate*/ = [%1]
    set @taxdt
    /*Select 1 from jdt1 w where w.TaxDate*/ = [%2]
    SELECT
    'company1' AS 'Company',
    T1.CardCode  AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    T0.RefDate AS 'Pstg Dt',
    T0.TaxDate AS 'Doc Dt',
    CASE
             WHEN T0.TransType = 13 THEN 'IN'
             WHEN T0.TransType = 14 THEN 'CN'
             WHEN T0.TransType = 30 THEN 'JE'
             WHEN T0.TransType = 24 THEN 'RC'
             WHEN T0.TransType = 46 THEN 'PS'
             ELSE 'Error ! ! !'
    END AS 'Doc Type',
    T0.Ref1 'Doc. Number',
    ISNULL(T0.FCCurrency, ' - ') AS 'Ccy',
    (T0.FCDebit - T0.FCCredit) AS 'Orig. F.Ccy',
    (T0.BalFcDeb - T0.BalFcCred) AS 'Bal. F. Ccy',
    (T0.Debit - T0.Credit) AS 'Orig. Rs',
    (T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',
    /* ########################  PROBLEM is here   ################## */
    CASE
                   WHEN (@refdt is not null) and (@taxdt is null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                   WHERE DateDiff(mm, T0.RefDate, @refdt) = 0 ) ,0)
                   WHEN (@refdt is null) and (@taxdt is not null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                    WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 0 ) ,0)
    END AS 'Current Mth', 
    CASE
                   WHEN (@refdt is not null) and (@taxdt is null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                   WHERE DateDiff(mm, T0.RefDate, @refdt) = 1 ) ,0)
                   WHEN (@refdt is null) and (@taxdt is not null)
                   THEN ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred
                    WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1 ) ,0)
    END AS '1 Mth Ago'
    /* Similarly for other age buckets  */
    FROM company1.dbo.JDT1 T0
    INNER JOIN company1.dbo.OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN company1.dbo.OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN company1.dbo.OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN company1.dbo.OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN company1.dbo.ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C' and Balance != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0

    HI
    I generate the next aged analysis
    CREATE PROCEDURE [dbo].[Aged_Analysis] (@end datetime,@Client VarChar (20)) AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    Declare @SAPUNION Table (SN VarChar(50), TransId Int, ReconSum Decimal(19,2), DebHab VarChar(1),
                                       Linea Int)
    insert into @SAPUNION
    SELECT X0.ShortName 'SN', X0.TransId 'TransId', SUM(X0.ReconSum)'ReconSum', X0.IsCredit 'DebHab', X0.TransRowId 'Linea'
                FROM ITR1 X0
                INNER JOIN OITR X1 ON X1.ReconNum = X0.ReconNum
                WHERE X1.ReconDate <= @end  AND X1.CancelAbs = ''
                GROUP BY X0.ShortName, X0.TransId, X0.IsCredit, X0.TransRowId
    SELECT T0.CardCode, T0.CardName,T0.Address,T0.CreditLine,
    T1.TransId , T4.BaseRef , T1.Ref2 , T1.RefDate, T1.DueDate,
    CASE
          WHEN T3.DebHab = 'D'  THEN T1.Debit-T1.Credit-T3.ReconSum
          WHEN T3.DebHab = 'C'  THEN T1.Debit-T1.Credit+T3.ReconSum
          ELSE (T1.Debit-T1.Credit)
    END 'Balance',
    CASE
           when DateDiff(Day,t1.RefDate,GetDate()) <= 30 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.RefDate,GetDate()) <= 30 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.RefDate,GetDate()) <= 30 then (T1.Debit-T1.Credit) end '0-30 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 31 and 45 then (T1.Debit-T1.Credit) end '31-45 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 46 and 60 then (T1.Debit-T1.Credit) end '46-60 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) between 61 and 75 then (T1.Debit-T1.Credit) end '61-75 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) BETWEEN 76 AND 89 then (T1.Debit-T1.Credit) end '76-89 dias',
    CASE
           when DateDiff(Day,t1.refdate,GetDate()) >90 and T3.DebHab = 'D'  then T1.Debit-T1.Credit-T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) >90 and T3.DebHab = 'C'  then T1.Debit-T1.Credit+T3.ReconSum
           when DateDiff(Day,t1.refdate,GetDate()) >90 then (T1.Debit-T1.Credit) end '90-Mas',
    CASE T1.TransType
          WHEN '13' THEN (SELECT Y.Comments FROM OINV Y WHERE Y.TransId = T1.TransId)
          WHEN '14' THEN (SELECT Y.Comments FROM ORIN Y WHERE Y.TransId = T1.TransId)
          WHEN '24' THEN (SELECT Y.Comments FROM ORCT Y WHERE Y.TransId = T1.TransId)
          ELSE T1.LineMemo
    END 'Comments'
    FROM OCRD T0
          INNER JOIN JDT1 T1 ON T1.ShortName = T0.CardCode
          INNER JOIN OACT T2 ON T2.AcctCode = T1.Account
          INNER JOIN OJDT T4 ON T4.TransId = T1.TransId
          LEFT JOIN OINV T5 ON T5.TransId = T4.TransId  and t5.ObjType = t4.TransType     
          LEFT JOIN @SAPUNION T3 ON T3.TransId = T1.TransId AND T3.SN = T1.ShortName AND T3.Linea = T1.Line_ID
    WHERE T0.CardType = 'C' /*FOR CLIENTS*/ AND T1.RefDate <= @end AND T2.AcctCode = /*YOUR CLIENT ACCOUNT*/ AND
    (CASE
          WHEN T3.DebHab = 'D' THEN (T1.Debit-T1.Credit-T3.ReconSum)
          WHEN T3.DebHab = 'C' THEN (T1.Debit-T1.Credit+T3.ReconSum)
          ELSE (T1.Debit-T1.Credit)
    END) != '0'
    AND T0.CardCode= @Client
    ORDER BY T0.CardCode,T1.TransId,t1.Ref2
    END
    AND Execute by SAP
    DECLARE @VAR INT, @DATE DATETIME, @BP VARCHAR(8)
    SET @VAR = (SELECT TOP 1 T.DocEntry FROM [dbo].[OINV] T WHERE T.DocDate <='[%0]' AND T.CardCode='[%1]')
    SET @DATE = '[%0]'
    SET @BP = '[%1]'
    EXECUTE [dbo].[Aged_Analysis]
    @end = @DATE,
    @Client = @BP
    Regards
    Floyola
    Edited by: Floyola on Jul 22, 2011 10:17 AM

Maybe you are looking for

  • How to clear one time vendor

    Morning when posting one vendor, it credits one G/L and debits the other. how do i clear them? Regards

  • Call Custom JSP from Screenflow JSP

    I need to call a static custom JSP(JSP2.jsp) from Screen flow JSP(JSP1.jsp) in Oracle BPM Studio while running Workspace. How do I do it? What will be the context path of JSP2.jsp while running workspace? JSP1.jsp has some context path created by Wor

  • Multiple T Codes to check User Authorization

    Dear All, I had requirement to check the list of tcodes assigned to the users. Here the input is multiple tcodes(i.e, more than 10 tcodes). Please provide your inputs / suggestions in this regard. Regards, Venkatesh

  • GAP ANALYSIS EXAMPLES WITH RESPECT TO.

    Hi, Please send me the scenarios and solutions to following topics in SD. 1)Creating Condition Table, Access Sequence, Condition Types and pricing procedure. Pricing Procedure Determination. 2)Defining Sales Document Types and Number Ranges for Sales

  • Need to reinstall ical

    ical will not open anymore: "application is damaged or incomplete". downloaded ical from apple wep 1.5.5, but installation is not possible. what do i do wrong or how can i get back my ical on my mac book pro?