Count in a query

Hi,
I have defined a query with characteristics Material No., Company Code and Key Figure1.
I would like to count the Material No. per Company Code for different ranges of Key Figure 1. Different ranges of Key Figure 1 could be <100 PC or > 100PC
The Query should give result the no. of Material per Company Code for key figure 1 <100 PC and > 100 PC
I have already count the Material no. in the query using Formula Variable with Processing Type Replacement Path.
How I can count the material No. per Company Code for the key Figure 1 with ranges (<100 PC or > 100 PC)?
Thanks

Moha,
Create a formula and use boolean operation.
For Qty< 100 PC :
(if qty < 100) * Material count " gives material count.
If qty is less than 100 then out put is: 1 * 1(if material count is 1).
Hope it Helps
Srini

Similar Messages

  • Returning a count from a query using Union

    Hi. I'm attempting to select a count from this query and then display the total in a message, but I'm getting a 'Too many rows returned' (ORA-01422). Can anyone tell me how I can achieve a total for this query?
             SELECT nvl(count(*),0)
           INTO conflict_cnt
           FROM dropper_assign
           WHERE dropper_id = :dropper_vacations.dropper_id AND
                trunc(sched_date) between :begin_dt and :end_dt
              union                          
       SELECT nvl(count(*),0)
        FROM exfc.bundle a, splits b
        WHERE a.bundle = b.bundle AND
             b.dropper_id = :dropper_vacations.dropper_id AND
             trunc(a.actual_dt) between :begin_dt and :end_dt;
              call_alert.the_error('test: '||to_char(conflict_cnt));Any help would be greatly appreciated.

    Thanks Christian, I can know return to my favourite present occupation named HOLIDAYS ;)
    btw with count function as the first message
    WITH
      data AS
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 10
        UNION
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 20
    SELECT
      SUM(cnt)
    FROM
      data
    SUM(CNT)              
    30        
    /* and */
    WITH
      data AS
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 10
        UNION ALL /****** returns me also 30 *****/
        SELECT
          COUNT(*) cnt
        FROM
          dual
          CONNECT BY level <= 20
    SELECT
      SUM(cnt)
    FROM
      data
    SUM(CNT)              
    30       result will defer only if both count return exactly the same value so definitely UNION ALL for that case or the simple solution I have provided before ...
    but leave it. that's enough messages for this thread ;)
    Jean-Yves
    Edited by: JeanYves Bernier on 9 août 2011 17:42

  • How can I evaluate the count of a query I'd like to execute with a map...

    Hi. I have a problem with a query...
    I hava created a query which a execute with a Map (I use the
    executeWithMap(Map) method). The problem is that sometimes this query
    returns a large resultset. So, I would like to execute an other query
    (called query_count) before executing ther final query with the Map. If
    the query_count returns a count < 200, I execute the final query. How can
    I do ? There is an example I have read this in the documentation :
    Query query = pm.newQuery (Magazine.class, "price < 5");
    query.setResult ("count(this)");
    Long count = (Long) query.execute ();
    The problem in this example is that the query is not execute with a Map.
    So my question is : "How can we do the evalute the count of a query we
    would like to execute with a map ?". Thank you for any response.

    Hi John,
    You should be able to executeWithMap that query, too. Is that giving you
    problems?
    Note that there may be an easier solution. What do you do if there are more
    than 200 results? If, e.g., you just get the first N, then one option is to
    set the FetchBatchSize on the query to N (thus activating large result set
    support), and then call size () on the resulting Collection. This will
    issue a SELECT COUNT(*) to the database to determine the size automatically.
    Thanks,
    Greg
    "John" <[email protected]> wrote in message
    news:ctq9a8$4gr$[email protected]..
    >
    Hi. I have a problem with a query...
    I hava created a query which a execute with a Map (I use the
    executeWithMap(Map) method). The problem is that sometimes this query
    returns a large resultset. So, I would like to execute an other query
    (called query_count) before executing ther final query with the Map. If
    the query_count returns a count < 200, I execute the final query. How can
    I do ? There is an example I have read this in the documentation :
    Query query = pm.newQuery (Magazine.class, "price < 5");
    query.setResult ("count(this)");
    Long count = (Long) query.execute ();
    The problem in this example is that the query is not execute with a Map.
    So my question is : "How can we do the evalute the count of a query we
    would like to execute with a map ?". Thank you for any response.

  • Count(*) with nested query

    Hi,
    I have a question about the count(*) with nested query.
    I have a table T1 with these columns:
    C1 number
    C2 number
    C3 number
    C4 number
    C5 number
    (The type of each column is not relevant for the example.)
    This query:
    select C1, C2, C3, C4
    from T1
    group by C1, C2
    it's not correct becausa C3 and C4 are not columns specified in the GROUP BY expression.
    If if run this query:
    select count(*)
    from (select C1, C2, C3, C4
    from T1
    group by C1, C2)
    I haven't an error message (the result is correctly the number of records).
    Why?
    Thanks.
    Best regards,
    Luca

    Because you are just selecting count(*) and none of the columns from the subquery, Oracle is optimising it by ignoring the selected columns and just running the sub query with the group by columns. I know it seems odd, but if you take a basic example:
    SQL> ed
    Wrote file afiedt.buf
      1  select count(*)
      2  from (select empno, sal, mgr, deptno
      3  from emp
      4* group by deptno)
    SQL> /
      COUNT(*)
             3... all columns but deptno are ignored
    ... but if you include one of the other columns, even if you group by that column...
    SQL> ed
    Wrote file afiedt.buf
      1  select count(*), empno
      2  from (select empno, sal, mgr, deptno
      3  from emp
      4  group by deptno)
      5* group by empno
    SQL> /
    group by empno
    ERROR at line 5:
    ORA-00979: not a GROUP BY expression
    SQL>... the error returns, because you're forcing oracle to include the column in the subquery.

  • Column count of dynamic query

    how can ı find column count of dynamic query
    is there a simple way
    thanks

    You can use DBMS_SQL to facilitate this:
    CREATE OR REPLACE FUNCTION count_sql( p_sql IN CLOB )
    RETURN INTEGER
    AS
            lv_cursor_id    INTEGER;
            lv_columns      DBMS_SQL.DESC_TAB;
            lv_column_count INTEGER;
    BEGIN
            -- Open Cursor
            lv_cursor_id := DBMS_SQL.OPEN_CURSOR;
            -- Parse Cursor
            DBMS_SQL.PARSE
            ( c             => lv_cursor_id
            , statement     => p_sql
            , language_flag => DBMS_SQL.NATIVE
            -- Describe Columns
            DBMS_SQL.DESCRIBE_COLUMNS
            ( c       => lv_cursor_id   
            , col_cnt => lv_column_count
            , desc_t  => lv_columns
            -- Close Cursor
            DBMS_SQL.CLOSE_CURSOR(lv_cursor_id);
            RETURN lv_column_count;
    END count_sql;
    /Example:
    SQL > SELECT * FROM V$VERSION;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL > SELECT count_sql('SELECT dummy, dummy, CASE WHEN dummy = ''X'' THEN 1 ELSE 0 END AS col FROM DUAL') FROM DUAL;
    COUNT_SQL('SELECTDUMMY,DUMMY,CASEWHENDUMMY=''X''THEN1ELSE0ENDASCOLFROMDUAL')
                                                                               3
    SQL > SELECT count_sql('SELECT dummy, dummy, dummy, ''Y'' FROM DUAL') FROM DUAL;
    COUNT_SQL('SELECTDUMMY,DUMMY,DUMMY,''Y''FROMDUAL')
                                                     4Hope this helps!

  • How to return the record count of a query to a number variable

    How would I get the record count from a query without using a cursor to step through the query and count the records individually?
    query: select * from table1 where column1 = column2
    How would I get the record count of the query above?
    thanks,
    michelle

    I figured it out
    select count(*) into theCount
    from ( select * from table1 where column1=column2 );
    thanks,
    michelle

  • Getting a record count in a query using UNIQUE

    I need to know how to grab a record count for a query so I can pass it back into the recordset.
    This select query uses UNIQUE to rollup the 555 records to 125 unique rows.
    But how would I do a record count.
    Do I pass the query to a cursor and then count the records in the cursor?
    Please detail your help please.
    Thank you in advance.

    SELECT unique
         CE.DATE_OF_SERVICE AS DOS_FROM
         ,CE.SERVICE_END_DATE AS DOS_TO
         ,CE.EVENT_SERVICE AS SERVICE_TYPE
         ,CN.CREATE_DATE_TIME
         ,CN.CASE_NOTE_ID
         ,CN.CASE_ID
         ,CN.EVENT_ID
         ,CN.REASON
         ,CN.CREATOR_USER_ID AS CREATOR_ID_USED
         ,CN.ROWID AS ROW_ID
         ,(SELECT Retrieve_Note2(CN.CASE_ID,CN.CASE_NOTE_ID) from DUAL) AS NOTE
    FROM
         MEMBER_TO_PATIENT MTA,
         CARE_EVENT CE,
         CASE_NOTES CN
    WHERE
         MTA.SUBSCRIBER_LID = '1260016473015' AND
         MTA.CASE_ID = CN.CASE_ID AND
         CN.EVENT_ID = CE.EVENT_ID
    ORDER BY
         CN.CASE_NOTE_ID DESC

  • Create a counter(in a query) by how many unique items are in a document num

    Hi,
    Is there a way for me to create a counter(in a query) by how many unique items are in a document number?
    If you look at the bold amounts below they have two unique item numbers 3 & 11. Because of that data is being duplicated in the InfoSet. The Subtotal needs to be 13500 instead of 27000. The two subtotals above are correct. I was thinking if I can create a create a counter(in a query) by how many unique items are in a document number (in this case it would be 2). And then if i divide Quantity by that counter, i shall get the correct value of 13500.
    How can i do this?
    Thanks
    Doc Num                  Item #       Quantity
    5900001759     11     2,700
    5900001759     11     5,400
    5900001759     11     2,700
    5900001759     11     2,700
    5900001759          13,500
    5900001890     7     2,700
    5900001890     7     5,400
    5900001890     7     2,700
    5900001890     7     2,700
    5900001890          13,500
    5900002176     3     2,700
    5900002176     11     2,700
    5900002176     3     5,400
    5900002176     11     5,400
    5900002176     3     2,700
    5900002176     11     2,700
    5900002176     3     2,700
    5900002176     11     2,700
    5900002176          27,000          
                             54,000

    Create a New Calculated Key Figure
    From the context menu for the Formula Variable, choose New Variable
    Choose the Processing type as Replacement Path
    In the next screen, select the Characteristic Info Object based on which the number of documents is to be displayed in the report (For example: Document Number / Order Number).
    Choose Next.
    In the Replace Variable with drop down box, choose Attribute Value.
    In the Attribute drop down, select Characteristic Reference (Constant 1).
    Choose Next.
    On the Save Variable page, an overview of the settings made for the variable will be displayed.
    Confirm the entries and Choose Finish.
    Open the formula variables directory and use Drag & Drop to transfer the formula variable
    To avoid the warning message, the formula variable is multiplied by 1
    The most important step here is to set the Time of Calculation to After Aggregation in the KF properties.
    (by Default the Time of Calculation is set to After Aggregation)
    The new calculated key figure is available under Calculated Key Figure in the Key Figure directory, and can be included in the query definition using Drag & Drop.
    Hope this help
    Rgds

  • Showing column value as counter in sql query - report

    I created a classic report with search bar based on an sql query. I would like to show the "notes" column in this query using some sort of counter and as a hyperlink to another section on the page (same idea as footnotes in a book). So if I have 10 rows and 5 have "notes". I should show 1,2,3,4,5 in the notes column for those rows and the number gets displayed as a link to another section listing the notes 1 through 5.
    I was thinking of creating a hidden page item as the counter with value of 0 and then in my query doing counter+1 but i'm not sure how to do this or if i can do that...
    If anyone can help or have any other ideas I would really appreciate it!!
    Thanks,
    Hindy

    Well, I'm doing this in VB and the subquery is dynamic. I'm passing an ADO recordset to a routine that sets up a listview to display the results. The number of columns selected can vary. My idea was to size the columns appropriately based on the size of the data. Within the display routine I could:
    sql = "SELECT "
    for i = 0 to oRS.Fields.Count - 1
    sql = sql & "MAX(LENGTH(" & i & ")), "
    next 'i
    sql = sql & "FROM (" & oRS.Source & ")"

  • Count of a query in Unix environment and use sysdate

    hi,
    i have a code below and i want this to be used in Unix env and i need to use sysdate where i hard coded the date but the time should remain as it is.
    select count(type),type from ebizp.bchistevent
    where (type = 'com.avolent.apps.event.LoginEvent' or type = 'com.avolent.apps.event.LogoutEvent')
    and(to_char(createdt, 'dd/mm/yy hh24:mi s') between '28/01/13 08:00:00' and '28/01/13 09:00:00')
    AND ( bucket = to_char(sysdate-1, 'YYYYMM') OR bucket = to_char(sysdate, 'YYYYMM') OR bucket = 0)
    group by type
    like it should be between 'sysdate 08:00:00' and 'sysdate 09:00:00')
    please suggest.

    Dates should be compared with dates values. Don't use to_char to compare date values.
    And dont use "TYPE" as a column name - it is a reserved key word..
    select count(type), type
    from ebizp.bchistevent
    where (
        type = 'com.avolent.apps.event.LoginEvent'
        or type     = 'com.avolent.apps.event.LogoutEvent'
    AND createdt BETWEEN trunc(sysdate)+(8/24) AND trunc(sysdate)+(9/24)
    and (
      bucket = to_char(sysdate-1, 'YYYYMM')
      or bucket    = to_char(sysdate, 'YYYYMM')
      or bucket    = 0
    GROUP BY type;And you can simplify the query
    select count(type), type
    from ebizp.bchistevent
    where type in
        ('com.avolent.apps.event.LoginEvent','com.avolent.apps.event.LogoutEvent')
    AND createdt BETWEEN trunc(sysdate)+(8/24) AND trunc(sysdate)+(9/24)
    and bucket in
         (to_char(sysdate-1, 'YYYYMM'),to_char(sysdate, 'YYYYMM'),'0')
    GROUP BY type;Edited by: jeneesh on Feb 19, 2013 2:42 PM

  • How to get count(*) in ABAP Query...

    Hi All,
    Can someone of you tell me, how to do the following in the ABAP Query. I want to get the count of records retreived during the query execution and display it in the output.
    example:::   Select count(*) from VBRK.
    Thanks a lot.
    Thanks!
    Puneet.

    From help doc:
    Note
    The SELECT COUNT( * ) FROM ... statement returns a result table containing a single line with the result 0 if there are no records in the database table that meet the selection criteria. In an exception to the above rule, SY-SUBRC is set to 4 in this case, and SY-DBCNT to zero.
    You can just run SELECT COUNT (*) FROM TABLE
    Number of rows is returned in SY-DBCNT
    Edited by: Kevin Lin on Jul 2, 2008 10:55 PM

  • Equipment count incorrect in query

    Hello BI Gurus,
    We are facing the following problem. I have a report requirement in the following format.
                         Sep-07     Oct-07     Nov-07     Dec-07
    Total No of Machines      11     11     12     12
    Machines relate to Equipment here. I am extracting this data from 0equipment_attr. This report is for a given Region, Plant and for a particular type of machine.
    The problem here is as follows.
    Let us suppose that equipment moves from plant X  to another plant Y in September and later to plant Z.
    Equipment should reflect the changes in Total number of machines.
    Currently, Equipment has "From" and "To" date. Based on this, I am getting this value in calmonth,
    let us say for example for
    Equipment                 From date                 To Date                  Calmonth     Plant
    400000          17.07.2008     01.01.1000     
    400000          24.12.2008     18.07.2008     07.2008     1101
    400000          31.12.9999     25.12.2008     12.2008     1103
    Though, I am getting Calmonth correctly to indicate the status of the equipment present for that month..
    I have 2 problems, first of all, at query level, it just shows 1 record with the latest month that is in this case , Dec 2008. but incase of equipment master i do see both the records..
    In my reporting requirement, It needs to have history data over 12 months, so a given equipment will not indicate the status correctly..
    As we see in the above example, equipment 400000 is moved from plant 1101 to 1103, when i look at query, it just shows me one record which is the latest..
    I believe the problem here is with time dependency. calmonth is time dependent attribute in 0equipment, if i turn it time independent, all the values in calmonth will be same, i.e 12.2008 which should not be the case..
    So in short there are 2 problems, how do i get the correct status of equipment at monthly level with the current scenario and second one will be for the months where there is no movement of equipment, it should show the correct count of equipment.,.
    Please advice..
    Thanks in advance,

    Hi Vipul,
                 Check this url.....
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/009819ab-c96e-2910-bbb2-c85f7bdec04a
    Thanks,
    Vijay.

  • Count column in query

    Hi all,
    I work with forms 6i and database oracle 8. I want to know if it's possible to count the number of column in a sql query. For exemple, i have : "select id, name, dtbirth from table". In this query, I have 3 column. But I don't know how can I get it! Someone can help me! please!
    best regards.

    You are in the wrong forum, try the database forum.
    Steven Davelaar,
    JHeadstart Team.

  • How can I get record count with a query?

    In Client/Server pplication,the client send a query to server.
    How can server get record count by oracle call interface?
    Is it need execute "select count(*) from ...."?

    Yes.
    Either that or increment a counter for each record fetched and
    loop round until you hit the last record.
    The first method would be more efficient on large datasets.

  • Reading count of a query in formula columns

    I need to supress a field/label from being displayed in the report output if the count of rows returned from another query is 0. I was thinking of defining a formula column that will have the count. Then can I use that formula column in the trigger of the field/label that I want to supress?
    I am all set. Was able to do with Summary columns.
    Message was edited by:
    M@$$@cHu$eTt$

    Dates should be compared with dates values. Don't use to_char to compare date values.
    And dont use "TYPE" as a column name - it is a reserved key word..
    select count(type), type
    from ebizp.bchistevent
    where (
        type = 'com.avolent.apps.event.LoginEvent'
        or type     = 'com.avolent.apps.event.LogoutEvent'
    AND createdt BETWEEN trunc(sysdate)+(8/24) AND trunc(sysdate)+(9/24)
    and (
      bucket = to_char(sysdate-1, 'YYYYMM')
      or bucket    = to_char(sysdate, 'YYYYMM')
      or bucket    = 0
    GROUP BY type;And you can simplify the query
    select count(type), type
    from ebizp.bchistevent
    where type in
        ('com.avolent.apps.event.LoginEvent','com.avolent.apps.event.LogoutEvent')
    AND createdt BETWEEN trunc(sysdate)+(8/24) AND trunc(sysdate)+(9/24)
    and bucket in
         (to_char(sysdate-1, 'YYYYMM'),to_char(sysdate, 'YYYYMM'),'0')
    GROUP BY type;Edited by: jeneesh on Feb 19, 2013 2:42 PM

  • Getting Counts with single query

    HI,
    I need help in writing a query that gets account counts in a single query,
    CREATE TABLE ACCOUNTINFO(     
    ACCOUNTID VARCHAR2(20 BYTE) NOT NULL,
    ACCOUNTNO VARCHAR2(10 BYTE) NOT NULL,
    LAST_DEPOSIT_DATE DATE,
    BALANCE NUMBER(10,0));
    I have a table like above and I am trying to write a query that gets
    Count of accounts with deposits made in last 1 month,
    Count of accounts with deposits made in last 2 months
    Account Count with balance > 0,
    Also, I need to join this ACCOUNTINFO with ACCOUNTMAIN to get name etc details
    CREATE TABLE ACCOUNTINFO(     
    EMPID VARCHAR2(20 BYTE) NOT NULL,
    FNAME VARCHAR2(30 BYTE) NOT NULL,
    MNAME VARCHAR2(30 BYTE),
    LNAME VARCHAR2(30 BYTE) NOT NULL,
    DOB DATE,
    ACCOUNTID VARCHAR2(20 BYTE));
    Question, how to write a query since I getting too-many counts (I have only 3 in sample above, actual goes on like 3-6, 6-9 etc).

    SELECT SUM  (CASE WHEN LAST_DEPOSIT>=ADD_MONTHS(SYSDATE,-1) THEN
                   1
                 ELSE
                   0
                 END
                ) COUNT_LAST_MONTH,
           SUM  (CASE WHEN LAST_DEPOSIT>=ADD_MONTHS(SYSDATE,-2) THEN
                   1
                 ELSE
                   0
                 END
                ) COUNT_LAST_TWO_MONTHS,
           SUM  (CASE WHEN BALANCE>0 THEN
                   1
                 ELSE
                   0
                 END
                ) COUNT_BALANCE_GREATER_ZERO
      FROM ACCOUNTINFO

Maybe you are looking for

  • Complete newbie to postfix, some guidance?

    What I'm aiming for is a mailserver that will allow me to send/receive mail both locally and through the Internet. I will be ending my hosting with my provider (money issues) and need to transfer all my existing stuff to my home box, with DynDNS givi

  • Ipad 3

    I am having trouble entering new banking information into my Apple ID on my ipad 3. The error msg is information doesn't match our records.

  • Cannot download abap webdynro  trial version from sdn

    I am unable to download the netweaver abap webdynpro trial version from SDN .I am using the link in Download section connection gets reset after some time. Can some one plz let me know how to download this Edited by: rahul v on Mar 19, 2008 6:25 PM

  • Issues with Prologix GPIB to Ethernet not being recognized by MAX

    My client has a Prologix GPIB to Ethernet interface and MAX does not recognize it. Anyone deal with this? Labview 2012 SP1 and latest Prologix drivers.

  • I hade 2.00 on itunes now i have 59.

    Dear Apple I hade $2.00 on itunes and now wen i went to buy a song for 99. my iphone told me i hade $0.59 credit help