Urgent! group by query based on a logical OR (bitwise)

Let's say I have the following table:
field: f1 f2 f3 f4 f5
record 1: a a 1 0 4
record 2: a b 2 3 7
record 3: a b 0 8 1
I want to make a group by on f1 so that I get just one record which is:
field: f1 f3 f4 f5
record 1: a 3 11 7
where the result of each field is actually a group by based on a logical OR (bitwise)
ie:
3 = 1 or 2 or 0
11 = 0 or 3 or 8
7 = 4 or 7 or 1
any suggestion ?
Thank you

You can try using DECODE
e.g.
Select F1,
            Sum( Decode( F3, 1,1,  2,2,  0) ) F3,
            Sum( Decode( F4, 3,3,  8,8,  0) ) F4,
            Sum( Decode( F5, 7,7,   0) ) F5
  from your_table
group by F1
I want to make a group by on f1 so that I get just one record which is:
field: f1 f3 f4 f5
record 1: a 3 11 7
where the result of each field is actually a group by based on a logical OR (bitwise)
ie:
3 = 1 or 2 or 0
11 = 0 or 3 or 8
7 = 4 or 7 or 1
any suggestion ?
Thank you

Similar Messages

  • Additional i/o fields to infoset query based on PNPCE logical database

    Hi All,
    I have a requirement to add two additional input and output fields "job function" and "job family" to a infoset query based on logical database PNPCE. I am new to writing code in infset query and there are so many code areas in infoset query. I am confused where to write code and how to limit the output list based on the user selection to the additional fields "Job function" and "job family". have any one done this in the past?. is there sample code somewhere to do something similar to this?
    Your help will be much appreciated with points! (as per our community guidelines)
    Regards,
    Arul

    Hello Arul,
    Your question would be better answered if you post it in on of the Business Intelligence Forums. Please close this thread and goto:
    Expert Forums » Business Intelligence
    or
    /community
    Regards,
    Manny

  • Grouping Inner Query based on a column.Please help

    I have a strange query.
    I am using Subquery to display the count of rows from the inner query
    depending upon the value of 'Y' or 'N'
    Trade
    id_entity       id_inst_code_type   id_inst_code   dt_trade
    AGL            SE                  5660249        10-Feb-06
    AGL            SE                  5660249        13-Feb-06
    AGL            SE                  5660249        13-Feb'06
    Instrument_xref
    ID_inst      id_inst_xref_type     id_inst_xref  flg_active
    0029010             SE          5660249          Y
    0070789          SE          5660249          Y
    0071190          SE          5660249          Y
    0072385          SE          5660249          Y
    0073215          SE          5660249          Y
    0084797          SE          5660249          Y
    0091375          SE          5660249          Y
    0094690          SE          5660249          Y
    0104438          SE          5660249          Y
    My output:
    id_inst_code_type          id_inst_code   Earliest    Latest       Total    Active
    SE                         5660249       10 Feb 06   13 Feb 06    3        9
    2) If all the 'flg_active' column in Table Instrument_xref is set to 'N'
       the Active should be 0.
    3) Assume that the flg_active could be 3 Y's and 6 N's then what?
    id_inst_code_type          id_inst_code   Earliest    Latest       Total    Active
    SE                         5660249       10 Feb 06   13 Feb 06    3        0
    How do I check for the 'Y' or 'N' value in my code below ?
    Help appreciated as the the functionality changes by the hour...
    select    tie.id_entity             'Entity',
              tie.id_inst_code          'Inst Code',
              min(tie.dt_trade)         'Earliest',
              max(tie.dt_trade)         'Latest',
              count(*)                  'Total',
              dt.InnerTotal             'Active'   
    from     trade_input_event tie,
    (Select  insx.id_inst_xref_type,
                   insx.id_inst_xref,
                   insx.flg_active,
                   count(*) InnerTotal
      from instrument_xref insx
      where insx.id_inst_xref = '5660249'
      ---** Do I need to Check the flg_active here..
      ---** Do I need to use the Having clause here? ie having count(insx.id_inst_xref) = 'N'
       group by insx.id_inst_xref_type,insx.id_inst_xref,insx.flg_active) dt
      where tie.id_inst_code = dt.id_inst_xref
      and tie.id_entity = 'AGL'
      group by tie.id_entity, tie.id_inst_code_type,tie.id_inst_code

    As the flg_active is set to 'Y', I am trying to set it to 'N' in the query
    so that count of 0 is returned, but this displays nothing.
    Please help as to how to display a count(*) of 0 when the flg_active is 'N'??
    Select  insx.id_inst_xref_type,
                   insx.id_inst_xref,
                   insx.flg_active,
                   count(*) InnerTotal
      from instrument_xref insx
      where insx.id_inst_xref = '5660249'
      and insx.flg_active = 'N'
      group by insx.id_inst_xref_type,insx.id_inst_xref,insx.flg_active) dt

  • Dynamic group membership Query based on alert description - IS package failed

    Hi there all good people,
    Ive got the following case:
    i need to filter out some of the alerts raised bij the is package failed Alert rule.
    All allerts raised need a override accept two alerts with a specific description. example:
    Alert description: Package "Full Back-Up" failed.  should still raise an alert also the
    Alert description: Package "Full Db Back-Up" failed.
    I.m playing arround with dynamic groups. Can somebody give me some pointers?
    Or do i need to create an new alert rule? en override this one for all objects?
    I hope the question is clear, im no native english speaking

    Hi,
    I would like to suggest you override this one for all objects and then create a new alert rule based on your requirement.
    Regards,
    Yan Li
    Regards, Yan Li

  • How to add a selection criterion to a SQ01 query based on logical database SDF?

    Hi,
    How should I add a selection criterion to a SQ01 query based on the logical database SDF? Is it possible through additional code? How to make use of the custom selection fields? I need a selection criterion based on BKPF-CPUDT (creation date).
    Thanks.

    Hi John,
    Please check the given below link in addtion to Atul post.
    http://scn.sap.com/community/erp/sd/blog/2012/04/16/query-report-tips-part-2--mandatory-selection-field
    Thanks,
    Senthil Maruthappan.

  • MDX calculation based on date logic for the Jan 1 of current year through the 15th of the previous month

    Hello, 
    We need some help with an SSAS MDX query based on date logic. One of the problems is that I don't have access to the Cube but have been given a query example with the logic needed for the calculation. Here's the scenario; 
    The ETL process will run on the first Tuesday after the 15<sup>th</sup> of a given month. The Analysis Cube data queried should include the current year up to the end of the previous month. For example, on May 19<sup>th</sup>
    (the first Tuesday on or after the 15th) the query should include data from January 1<sup>st</sup> through April 30<sup>th</sup>.
    The 15<sup>th</sup> of the month is not part of the query, it is a factor in when the query is run. The query will always be in terms of complete months.
    SELECT
                    NON EMPTY { [Measures].[Revenue Amount],
                    [Measures].[Utilization],
                    [Measures].[AVG Revenue Rate],
                    [Measures].[Actual Hours] }
    ON
                    COLUMNS,
                    NON EMPTY { ([dimConsultant].[User Id TT].[User Id TT].ALLMEMBERS * [dimConsultant].[Full Name].[Full Name].ALLMEMBERS * [dimConsultant].[Employee
    Type].[Employee Type].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION,
                    MEMBER_UNIQUE_NAME
    ON
                    ROWS
    FROM
                    ( SELECT
    ( { [dimDate].[Week Date].[1/4/2015], [dimDate].[Week Date].[1/11/2015], [dimDate].[Week Date].[1/18/2015], [dimDate].[Week Date].[1/25/2015], [dimDate].[Week Date].[2/1/2015] } )
                    ON
                                    COLUMNS
                    FROM
                                    ( SELECT
    ( { [dimIsBillable].[Is Billable].&[True] } )
                                    ON
    COLUMNS
                                    FROM
    [SSASRBA]
    WHERE
                    ( [dimIsBillable].[Is Billable].&[True], [dimDate].[Week Date].CurrentMember ) CELL PROPERTIES VALUE,
                    BACK_COLOR,
                    FORE_COLOR,
                    FORMATTED_VALUE,
                    FORMAT_STRING,
                    FONT_NAME,
                    FONT_SIZE,
                    FONT_FLAGS

    Hi Hans,
    Thank you for your question.  
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.  
    Thank you for your understanding and support. 
    Regards,
    Simon Hou
    TechNet Community Support

  • How to add a dynamic where clause for a sql based VO with group by query?

    Hi,
    Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
    vo.setWhereClause("type='MyType1' ");
    vo.executeQuery();
    Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
    Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
    Thanks,
    Chunyang
    Edited by: Chunyang on Dec 13, 2012 9:09 PM

    Hi,
    When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
    select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
    select * from (select empno, ename from emp) where ename='KING' - VALID
    select * from (select empno, ename from emp) where deptno=10  - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
    -Arun

  • How do I create a query based distibution group in Exchange 2010?

    Hi,
    We have just moved onto exchange 2010 and I wanting to create query based distribution groups based on OU's. As there is now wizard within 2010 I am a little unsure as to how to go about this. I am led to believe I now need a scritp to do this.
    Any help would be greatly appreciated.
    Thanks

    I have tried this and get the following error. Any Ideas?
    Delivery has failed to these recipients or groups:
    All@Doncaster <mailto:IMCEAEX-_O%3DFIRST%2B20ORGANIZATION_OU%3DEXCHANGE%2B20ADMINISTRATIVE%2B20GROUP%2B20%2B28FYDIBOHF23SPDLT%2B29_CN%3DRECIPIENTS_CN%3DAll%[email protected]>
    The email address that you entered couldn't be found. Check the address and try resending the message. If the problem continues, please contact your helpdesk.
    Diagnostic information for administrators:
    Generating server: CRHV03.crhfsg-uk.co.uk
    IMCEAEX-_O=FIRST+20ORGANIZATION_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=[email protected]
    #550 5.1.1 RESOLVER.ADR.ExRecipNotFound; not found ##
    Original message headers:
    Received: from CRHV03.crhfsg-uk.co.uk ([fe80::451b:a27f:42cb:f770]) by
     CRHV03.crhfsg-uk.co.uk ([fe80::451b:a27f:42cb:f770%12]) with mapi id
     14.01.0289.001; Fri, 15 Jul 2011 15:24:50 +0100
    Content-Type: application/ms-tnef; name="winmail.dat"
    Content-Transfer-Encoding: binary
    From: "Smith, Stacey" <[email protected]>
    To: "All@Doncaster" <[email protected]>
    Subject: FW: test
    Thread-Topic: test
    Thread-Index: AcxC+SC29u62U+fVRiGEfoRPRWVvRgAAc31g
    Date: Fri, 15 Jul 2011 15:24:50 +0100
    Message-ID: <[email protected]>
    References: <[email protected]>
    In-Reply-To: <[email protected]>
    Accept-Language: en-GB, en-US
    Content-Language: en-US
    X-MS-Has-Attach: yes
    X-MS-TNEF-Correlator: <[email protected]>
    MIME-Version: 1.0
    X-Originating-IP: [10.39.1.125]

  • Query based on Master datasource? - URGENT

    Hi Experts,
    Is it possible to create a query based on MASTER Datasource(Z master datasource)? if possible then how we can go or are there any setttings?...i got confused here..
    thanks in advance.
    regards,
    mahantesh

    If you mean an Infoobject masterdata record, you need to change the IO, Mater data/text tab, check charachter is data target/Infoprovider flag an activate the IO.
    Now you can use it in BEX
    Regards

  • SELECT QUERY  BASED ON SECONDARY INDEX

    Hi all,
    CAN ANYONE TELL ME HOW TO WRITE SELECT QUERY BASED ON SECONDARY INDEX.
    IN WHAT WAY DOES IT IMPROVE PERFORMANCE.
    i KNOW WHEN CREATING SECONDARY INDEX I NEED TO GIVE AN INDEX NO -iT SHOULD BE ANY NUMBER RIGHT?
    I HAVE TO LIST ALL PRIMARY KEYS FIRST AND THEN THE FIELD FOR WHICH I AM CREATING SECONDARY INDEX RIGHT?
    LETS SAY I HAVE 2 PRIMARY KEYS AND I WANT TO CREATE SEONDARY INDEX FOR 2 FIELDS THEN
    I NEED TO CREATE A SEPERTE SECONDARY INDEX FOR EACH ONE OF THOSE FIELDS OR ONE SHOULD BE ENOUGH
    pLS LET ME KNOW IF IAM WRONG

    HI,
    If you cannot use the primary index to determine the result set because, for example, none of the primary index fields occur in the WHERE or HAVINGclauses, the system searches through the entire table (full table scan). For this case, you can create secondary indexes, which can restrict the number of table entries searched to form the result set.
    You create secondary indexes using the ABAP Dictionary. There you can create its columns and define it as UNIQUE. However, you should not create secondary indexes to cover all possible combinations of fields.
    Only create one if you select data by fields that are not contained in another index, and the performance is very poor. Furthermore, you should only create secondary indexes for database tables from which you mainly read, since indexes have to be updated each time the database table is changed. <b>As a rule, secondary indexes should not contain more than four fields</b>, <b>and you should not have more than five indexes for a single database table</b>.
    <b>What to Keep in Mind for Secondary Indexes:</b>
    http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eb2d446011d189700000e8322d00/content.htm
    http://www.sap-img.com/abap/quick-note-on-design-of-secondary-database-indexes-and-logical-databases.htm
    Regards
    Sudheer

  • Select List (query based LOV) in a wizard created report form

    I have created an updatable report form with 3 columns:
    app_id
    user_id
    group_id
    Each app_id has multiple group_id's associated with it, and I want to show the group_id field as a Select List (query based LOV) that contains the groups associated with the app_id.
    My query for the select list needs to be similar to the following:
    SELECT DISPLAY_NAME, GROUP_ID
    FROM APPLICATION_GROUPS
    WHERE APP_ID = ?????
    ORDER BY 1
    The problem is, I don't know how to reference the app_id from the main report to replace the ?????.
    In other words, if my report returns 2 rows of data like this:
    app_id----------user_id----------group_id
    1-----------------24------------------3
    2-----------------24------------------15
    Then how do I get the group_id column to be a select list of possible groups for each application? If app_id 1 has 3 groups associated with it, 3, 4, & 5 and app_id 2 has 2 groups associated with it, 15 & 16, then those each of the select lists should be based on the app_id.
    Hopefully I explained this clearly.
    Thanks,
    Kris

    Leo,
    Thanks for the response, but I don't think you quite understand my problem. If I go to the Column Attributes screen for the group_id field, I have the "Display As" drop down set to "Select List (query based LOV)", not "Select List (named LOV)". This requires that the sql query be written in the "List of values definition" text area below. Within that text area I have the following query:
    SELECT DISPLAY_NAME, GROUP_ID
    FROM APPLICATION_GROUPS
    WHERE APP_ID = ?????
    ORDER BY 1
    The APP_ID that I need to reference is for the current row of data that is being processed. Therefore, I can't use a :PNNN_APP_ID variable, because that field does not exist on the page.
    Hopefully this explains it a little better.
    Thanks,
    Kris

  • Adhoc query based on HRP inofytpes with already existing PA

    Hi Experts,
    Is it possible to build a adhoc query based on the combination of PA & OM infotypes.
    Thanks in Advance
    Regards,
    IFF

    Hi,
    It is very much possible. Use the Logical database PCH for this while creating the infoset.
    Br/Manas

  • Urgent ---group by syntax error

    This is my syntax as below.But it doesn't work.Does anyone can tell me what's problem ? or it have another way to solve this quuestion? thanks .
    sql syntax:
    select a.txdate,a.costype,sum(cosamt) * (1+a.cosrate) as costamount
    from sales_cost a
    where a.txdate between '2003-01-01' and '2003-02-01'
    group by a.txdate,a.costype;

    Although more specifics might have helped, I am assuming based on the title of the post: "urgent ---group by syntax error" and my test of the original code that I have identified the error. See the example below for how the original code produces a group by error and how the solution I provided executes without error.
    SQL> -- test data:
    SQL> SELECT * FROM sales_cost
      2  /
    TXDATE      COSTYPE    COSAMT   COSRATE                                                            
    03-JAN-03         1         3        .5                                                            
    03-JAN-03         1         4       .25                                                            
    03-JAN-03         2         4       .75                                                            
    04-JAN-03         3         3        .5                                                            
    04-JAN-03         4         4       .25                                                            
    04-JAN-03         4         4       .75                                                            
    6 rows selected.
    SQL> --
    SQL> --
    SQL> -- wrong:
    SQL> SELECT   a.txdate, a.costype,
      2             SUM (a.cosamt) * (1 + a.cosrate) AS costamount
      3  FROM     sales_cost a
      4  WHERE    a.txdate BETWEEN '2003-01-01' AND '2003-02-01'
      5  GROUP BY a.txdate,a.costype
      6  /
             SUM (a.cosamt) * (1 + a.cosrate) AS costamount
    ERROR at line 2:
    ORA-00979: not a GROUP BY expression
    SQL> --
    SQL> --
    SQL> -- correct:
    SQL> SELECT   a.txdate, a.costype,
      2             SUM (a.cosamt * (1 + a.cosrate)) AS costamount
      3  FROM     sales_cost a
      4  WHERE    a.txdate BETWEEN TO_DATE ('2003-01-01', 'YYYY-MM-DD')
      5                   AND     TO_DATE ('2003-02-01', 'YYYY-MM-DD')
      6  GROUP BY a.txdate,a.costype
      7  /
    TXDATE      COSTYPE COSTAMOUNT                                                                     
    03-JAN-03         1        9.5                                                                     
    03-JAN-03         2          7                                                                     
    04-JAN-03         3        4.5                                                                     
    04-JAN-03         4         12                                                       

  • Query based on date partition

    Hi,
    I am trying to output only a successful job during the past 24 hrs of each day. If there is job that has an outcome of a success and a failure within the last
    24 hrs for each day, I want to only output the successful one. If there are no success for the same job, I will output the last attempted failed job.
    Here are my columns:
    current output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3400907     7/27/2012 10:01:09 AM     polA     target1          Failed          0     incr     clone1
    3389180     7/23/2012 10:01:14 AM     polA     target1          Failed          1     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3367074     7/22/2012 11:24:00 AM     polA     target1          Failed          1     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    336074     7/21/2012 10:01:08 AM     polA     target1          Success          0     incr     clone1
    desired output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    Here is a code I am trying to use without success:
    select *
    from
       (selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
              ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn
                   from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
       where rn = 1
       order by jobdate desc;Thanks,
    -Abe

    Hi, Abe,
    You're on the right track, using ROW_NUMBER to assign numbers, and picking only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
    You want to assign a #1 for each distinct combination of group_id, path, asset and calendar day , right?
    Then you need to PARTITION BY group_id, path, asset and calendar day . I think you realized that when you named this thread "Query Based *on date partition* ".
    The next thing is the analytic ORDER BY clause. To see which row in each partition gets assigned #1, you need to order the rows by outcome ('Success' first, then 'Failed'), and after that, by jobdate (latest jobdate first, which is DESCending order).
    If so, this is what you want:
    WITH     got_r_num     AS
         SELECT  j.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER ( PARTITION BY  group_id     -- GROUP is not a good column name
                                   ,                    path
                             ,             asset
                             ,             TRUNC (jobdate)
                                   ORDER BY          CASE  outcome
                                                 WHEN  'Succcess'
                                         THEN  1
                                         ELSE  2
                                             END 
                             ,             jobdate     DESC
                           )      AS r_num
         FROM    job_table  j
         WHERE     outcome     IN ('Success', 'Failed')
    --     AND     ...     -- Any other filtering, if needed
    SELECT     *       -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test it.
    It looks like you posted multiple copies of this thread.  I'll bet that's not your fault; this site can cause that.  Even though it's not your fault, please mark all the duplicate versions of this thread as "Answered" right away, and continue in this thread if necessary.
    Edited by: Frank Kulash on Jul 28, 2012 11:47 PM
    This site is flakier than I thought! I did see at least 3 copies of this same thread earlier, but I don't see them now.

  • Query based on date

    Have you guys ever tried to write a query based on CMP?
    The EJB QL is:
    select object(a) from ActionItems as a where a.duedate = ?1
    When I deployed it to OC4J, I got the following error:
    Error compiling D:\oc4j903\j2ee\home\applications\biogen/biogen.jar: Error trans
    lating EJBQL: Invalid type for expression (a.dueDate = ?1)
    EJB QL statement : 'select object(a) from ActionItems as a where a.dueDate = ?1'
    EJB QL method : public abstract java.util.Collection ActionItemsLocalHome.findByDueDate(java.sql.Date) throws javax.ejb.FinderException
    Auto-deploying file:/D:/oc4j903/j2ee/home/applications/biogen/biogen/ (Assembly
    had been updated)...
    So, any query that is based on date will not work for OC4J, is this a bug or what?
    Thanks for the reply.
    Jingzhi

    I would post this question (and your date range question) to the J2EE group. More J2EE/EJB specific questions are answered there.
    To my understanding the standard ejb2.0 specification is weak in date comparisons for queries. I believe you need to add your date queries to your application server specific orion-ejb-jar.xml file. I'm not sure of how, I would post that question to the J2EE forum, or look it up in the 9ias documentation.
    -Mark

Maybe you are looking for