Selecting Single Rows that match to a column within group function output

Trying to write a Query that will look through a data set that will return the Barcodes of CompoundNames that have a summed Quantity > 500.
So if it was ran against the sample table below the output would be
0005
0006
0007
0008
0009
0010
Barcode, CompoundName, BatchId, Quantity
0001, XE 1000, XE 1000 100, 100
0002, XE 1000, XE 1000 101, 100
0003, XE 1000, XE 1000 102, 100
0004, XE 1000, XE 1000 103, 100
0005, XE 2000, XE 2000 100, 100
0006, XE 2000, XE 2000 101, 100
0007, XE 2000, XE 2000 102, 100
0008, XE 2000, XE 2000 103, 100
0009, XE 2000, XE 2000 104, 100
0010, XE 2000, XE 2000 105, 100
0011, XE 3000, XE 3000 100, 100
I've got this far
Select CompoundName, SUM(QUANTITY) FROM Table
GROUP BY CompoundName
HAVING SUM(QUANTITY) > 500)
order by compoundname;
But I need each Barcode that corresponds to each batchid when the summed quantity of the batches is > 500.
TIA

Replacing a GROUP BY Aggregate function by analytic equivalent (using PARTITION BY)
will return every ROW (limited by where clause) but will not perform
actual "aggregation operation.
So it is possible that *selected result set* could contain duplicate row. Of course it depends on columns being seected and input data.
+Ofcourse OPs sample data returns the same result with or without DISTINCT+
For example...
*WITH DISTINCT*
{code}
sudhakar@ORCL>with t1 as
2 (select 0001 barcode,'XE0000' COMPOUNDNAME, 700 quantity FROM DUAL UNION ALL
3 select 0003 ,'XE1000' , 20 FROM DUAL UNION ALL
4 select 0003 ,'XE1000' , 280 FROM DUAL UNION ALL
5 select 0003 ,'XE2000' , 50 FROM DUAL UNION ALL
6 select 0003 ,'XE2000' , 100 FROM DUAL UNION ALL
7 select 0003 ,'XE2000' , 150 FROM DUAL UNION ALL
8 select 0003 ,'XE2000' , 200 FROM DUAL UNION ALL
9 select 0003 ,'XE2000' , 750 FROM DUAL UNION ALL
10 select 0003 ,'XE2000' , 120 FROM DUAL UNION ALL
11 select 0003 ,'XE1000' , 70 FROM DUAL
12 )
13 select distinct * from
14 (
15 Select Barcode, CompoundName, SUM(QUANTITY) over (partition by CompoundName) sumqty
16 FROM t1
17 )
18 where sumqty > 500
19 order by compoundname;
BARCODE COMPOU SUMQTY
1 XE0000 700
3 XE2000 1370
sudhakar@ORCL>
{code}
*WITHOUT DISTINCT*
{code}
sudhakar@ORCL>with t1 as
2 (select 0001 barcode,'XE0000' COMPOUNDNAME, 700 quantity FROM DUAL UNION ALL
3 select 0003 ,'XE1000' , 20 FROM DUAL UNION ALL
4 select 0003 ,'XE1000' , 280 FROM DUAL UNION ALL
5 select 0003 ,'XE2000' , 50 FROM DUAL UNION ALL
6 select 0003 ,'XE2000' , 100 FROM DUAL UNION ALL
7 select 0003 ,'XE2000' , 150 FROM DUAL UNION ALL
8 select 0003 ,'XE2000' , 200 FROM DUAL UNION ALL
9 select 0003 ,'XE2000' , 750 FROM DUAL UNION ALL
10 select 0003 ,'XE2000' , 120 FROM DUAL UNION ALL
11 select 0003 ,'XE1000' , 70 FROM DUAL
12 )
13 select * from
14 (
15 Select Barcode, CompoundName, SUM(QUANTITY) over (partition by CompoundName) sumqty
16 FROM t1
17 )
18 where sumqty > 500
19 order by compoundname;
BARCODE COMPOU SUMQTY
1 XE0000 700
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
3 XE2000 1370
7 rows selected.
sudhakar@ORCL>
{code}
vr,
Sudhakar B.

Similar Messages

  • Reorganize function will not allow "select rows that match"

    I'm trying to sort data in a sheet the same way excel lets you sort by using "filter"
    I'm told that using the Reorganize function will allow me to do this especially if I select the "select rows that match" options.
    The only problem is that that options is grayed out and I can't use it.
    Anybody else have any suggestions or instructions>?
    Thanks

    Make sure you have selected a table

  • Select single row in ALV grid

    ABAPer's ,
    Does anyone can guide me to select single row only in ALV grid , without OO.

    Hello,
    I did not get u.
    But check the below code it may help u.
    tables: mara.
    TYPE-POOLS: SLIS.
    data:repid like sy-repid.
    data: itb type mara occurs 0 with header line,
    IT_FIELDCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV WITH HEADER LINE,
    IT_LAYOUT TYPE SLIS_LAYOUT_ALV,
    ITB1 TYPE MAKT OCCURS 0 WITH HEADER LINE.
    selection-screen begin of block b.
    parameters: p_matnr type matnr.
    selection-screen end of block b.
    select * from mara into table itb where matnr = p_matnr.
    SELECT * FROM MAKT INTO TABLE ITB1 WHERE MATNR = P_MATNR.
    repid = sy-repid.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
       I_CALLBACK_PROGRAM             = repid
      I_CALLBACK_PF_STATUS_SET       = ' '
       I_CALLBACK_USER_COMMAND        = 'HANDLE_USER_COMMAND'
       I_STRUCTURE_NAME               = 'MARA'
       IS_LAYOUT                      = IT_LAYOUT
       IT_FIELDCAT                    = IT_FIELDCAT[]
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
      IT_EVENTS                      =
      IT_EVENT_EXIT                  =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      TABLES
        t_outtab                       = itb
    EXCEPTIONS
      PROGRAM_ERROR                  = 1
      OTHERS                         = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    FORM HANDLE_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE
    SLIS_SELFIELD.
    CASE R_UCOMM.
    WHEN '&IC1'.
    CLEAR IT_FIELDCAT[].
    IF RS_SELFIELD-FIELDNAME = 'MATNR'.
    READ TABLE ITB1 INDEX RS_SELFIELD-TABINDEX.
    WRITE: / ITB1-MAKTX.
    ENDIF.
    ENDCASE.
    ENDFORM. "HANDLE_USER_COMMAND
    Regards

  • Single row from this query without create a group by

    Can I have a single row from this query without create a group by on tipo (TIPO can have only 2 value (A,D)
    SELECT
    CASE TIPO
    WHEN 'D' THEN SUM(IMPORTO) ELSE 0 END DIMPORTO,
    CASE TIPO
    WHEN 'A' THEN SUM(IMPORTO) ELSE 0 END AIMPORTO
    FROM MGIORNALE
    WHERE K_CONTO = '100001' --CONTO
    AND DECODE(T_MOVIM,'MRAP',TO_DATE('31/12/'||to_char(a_competenza),'DD/MM/YYYY'),DATA_RG)
    -- BETWEEN DATAA AND DATAB
    BETWEEN '01/01/2006' AND '31/12/2006'
    --GROUP BY TIPO
    --AND TIPO = COL_conto
    Thanks in advance

    Is like this?
    sum (CASE TIPO
    WHEN 'D' THEN IMPORTO ELSE 0 END) DIMPORTO,

  • Extracting rows that match a certain criterion

    Hi guys,
    I realize that spreadsheet software has certain limitations, but I was hoping I could stretch it a tad bit, by asking if it's possible to take rows that meet a certain criterion and have them listed in another table.
    I've included an example wherein I take a list of a few well-known crypto characters and extract those that are not checked as evil (i.e., evil is FALSE) into a different list.
    http://pyth.net/hotlinking/cast-salaries.png
    I'd appreciate any suggestions; and thanks in advance for any time taken to respond.
    Regards,
    Friðrik Már

    We have posted a solution but now I have to find it. You can test for the "TRUE" / "FALSE" nature of the check box then show related row/column information using VLOOKUP, and IF statements. You could then filter for the presence of a value.
    =IF(A2=TRUE,VLOOKUP(...
    Regards,

  • Counting rows that match 2 criteria?

    I've been hunting for this since yesterday and I know it's gotta be something silly I'm just overlooking, but I'm very new to iWork and spreadsheets in general... any help would be greatly appreciated.
    Basically I've a simple table that tracks two items on each row: a trouble code and a time.
    What I need is a formula that will count all rows in which trouble code 5 occurred at 8pm. It seems like it would be easy... a COUNTIF with an AND statement? But I just can't get the syntax right, or maybe I'm just not picking the right function.
    Thanks!
    Jimmy

    sw33tjimmy wrote:
    Thank you. I had read about the COUNTIFS function, but for some reason I didn't see it in the list of options among all of the other stuff I was trying. It's confusing when formulas aren't standardized across the different spreadsheet platforms.
    Happily, they aren't standardized.
    The Ford T era is gone and I hope that it will never return.
    Yvan KOENIG (VALLAURIS, France) mardi 29 juin 2010 21:04:28

  • How to get sum in new row (not in a new column) in the query output ?

    There are values in a table like this:
    A B C D
    DEsc1 ID1 15 45
    DEsc2 ID1 10 67
    DEsc3 ID2 12 34
    Desc4 ID2 19 32
    How to achieve this output :
    A B C D
    DEsc1 ID1 15 45
    DEsc2 ID1 10 67
    --- ID1 25 112 <--- Sum of two rows corresponding to C and D whose B column is same
    DEsc3 ID2 12 34
    Desc4 ID2 19 32
    Desc5 ID2 10 12
    ----- ID2 41 78 <---- Sum of three rows corresponding to C and D whose B column is same

    SQL>WITH t AS
      2       (SELECT 'DEsc1' AS a, 'ID1' AS b, 15 AS c, 45 AS d FROM DUAL
      3        UNION ALL
      4        SELECT 'DEsc2', 'ID1', 10, 67 FROM DUAL
      5        UNION ALL
      6        SELECT 'DEsc3', 'ID2', 12, 34 FROM DUAL
      7        UNION ALL
      8        SELECT 'Desc4', 'ID2', 19, 32 FROM DUAL)
      9  SELECT   DECODE(GROUPING(a || ' ' || c || ' ' || d), 0, TO_CHAR(MAX(a)), '-----') AS a,
    10           MAX(b) AS b, SUM(c) AS c, SUM(d) AS d
    11      FROM t
    12  GROUP BY b, ROLLUP(a || ' ' || c || ' ' || d);
    A     B            C          D
    DEsc1 ID1         15         45
    DEsc2 ID1         10         67
    ----- ID1         25        112
    DEsc3 ID2         12         34
    Desc4 ID2         19         32
    ----- ID2         31         66Urs

  • Unable to reorder/change column names on interactive single row view

    I have created an interactive report and grouped my columns to display nicely in a single row view report. However, once I initially add the columns to a group, I am unable to reorder them. I can move them up and down the list, but the changes don't save. Also, I have gone through column by column and unchecked the box that says Use Same Text for Single Row View and expanded the column name. However, the single row view still displays what is in the master report. I've tried closing out my browser completely and reopening, but I am still not seeing my changes. Any suggestions?

    I also just stumbled about the "Use Same Text for Single Row View" option actually doing nothing - in Single Row View I still get the label text from "Column Heading", no matter what I enter in "Single Row View Label".
    I had to adjust a column width using a span tag in the heading (as this seems to be the only way to do that - any other suggestions I found adding style information to the region header had no effect), and now that tag is displayed in the Single Row View label.
    I can live with that for now, but it's not really nice.
    Is this a known bug? Didn't find anything else in the forum regarding this problem so far.
    Holger

  • How to select a row in a single-select table view?

    Hello folks,
    I have a table view with a 'details' button. When a row is selected and 'details' is pressed, the table view disappears and a form view is displayed (like the toggle button in PCUI). I have implemented this using a navigation link. When I press 'cancel' in the form view, another navigation link takes the user back to the table view.
    My problem is, when the table view reappears, there is no row selected (the row that was selected previously, is de-selected). How do I make sure that the row remains selected?
    I tried using the collection_wrapper->mark() method in the inbound plug of the table view, but it works only for multi-select table.

    Hi Masood,
    Thanks for your reply.
    I had already tried using MARK ( iv_index = lv_index ), but it did not work because the first statement in the MARK method is
      check ME->MULTI_SELECT = ABAP_TRUE.
    Mine is a single-select table. So, using the MARK of the iterator object, with either the IV_BO or the IV_INDEX parameter also does not work. Is there any other way for a table with single row selection?
    Thanks!!!
    Rohan.

  • Copy Function with Single selection of row

    I want to copy necessary Planning items in my Input ready query from period 1 to remaining periods based on variable entries.  To achieve this I have created a copy planning function to copy amount entered in period 1 (variable) to range of posting period variable entries (e.g. 2 -12 or 6-12).
    I have created structure for GL accounts and I want to copy from period 1 to 2 - 12 for one row at a time.
    I have created WAD template, I selected in behavior section of Analysis item, single with command option and assigned Planning sequence (consisting of copy function) as command.
    On execution of WAD, I select single row in my input ready query and instead of one row getting copied over to the range of posting period, all rows consisting of Planning Items with amount are getting copied over, which I am not expecting with single selection option.
    How can I have only one row getting copied over?
    Am I am missing something?
    Your suggestions are highly appreciated.
    Regards,
    Sachin

    Hello Gregor,
    Thanks for your response.  I tried what you have suggested and also followed the documentation, not sure why it is not working as expected
    In my variable I have characterictis such as:
    Version
    Fiscal Year
    Fiscal Year Variant
    Profit Center
    In my rows:
    Planning Item
    Columns:
    Period
    Amount
    In behavior I have selected Row Selection Single.  I am using Button group and assigned following:
    Command: Execute a Planning Function -> In Data Binding -> Selection Binding -> Characteristic -> Planning Item -> Binding Type -> Item Characteristic -> Web Item Selection -> Item Binding -> Query (Analysis Item) -> Characteristic -> Planning item.
    For Variable I have defined nothing.
    Do you think my settings are correct?
    Regards,
    Sachin

  • How to display rows of data into different columns?

    I'm new to SQL and currently this is what I'm trying to do: 
    Display multiple rows of data into different columns within the same row
    I have a table like this:
        CREATE TABLE TRIPLEG(
            T#              NUMBER(10)      NOT NULL,
            LEG#            NUMBER(2)       NOT NULL,
            DEPARTURE       VARCHAR(30)     NOT NULL,
            DESTINATION     VARCHAR(30)     NOT NULL,
            CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (T#, LEG#),
            CONSTRAINT TRIPLEG_UNIQUE UNIQUE(T#, DEPARTURE, DESTINATION),
            CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (T#) REFERENCES TRIP(T#) );
        INSERT INTO TRIPLEG VALUES( 1, 1, 'Sydney', 'Melbourne');
        INSERT INTO TRIPLEG VALUES( 1, 2, 'Melbourne', 'Adelaide');
    The result should be something like this:
    > T#  | ORIGIN  | DESTINATION1  |  DESTINATION2 
    > 1   | SYDNEY  | MELBORUNE     | ADELAIDE
    The query should include the `COUNT(T#) < 3` since I only need to display the records less than 3. How can I achieve the results that I want using relational views???
    Thanks!!!

    T#
    LEG#
    DEPARTURE
    DESTINATION
    1
    1
    Sydney
    Melbourne
    1
    2
    Melbourne
    Adelaide
    1
    3
    Adelaide
    India
    1
    4
    India
    Dubai
    2
    1
    India
    UAE
    2
    2
    UAE
    Germany
    2
    3
    Germany
    USA
    On 11gr2, you may use this :
      SELECT t#,
             REGEXP_REPLACE (
                LISTAGG (departure || '->' || destination, ' ')
                   WITHIN GROUP (ORDER BY t#, leg#),
                '([^ ]+) \1+',
                '\1')
        FROM tripleg
        where leg#<=3
    GROUP BY t#;
    Output:
    1 Sydney->Melbourne->Adelaide->India
    2 India->UAE->Germany->USA
    Cheers,
    Manik.

  • Projects only display single row when not in fullscreen

    Hi
    I've just updated to 3.4.5 an coincidentally used fullscreen for the first time so I'm not certain which action has caused this.
    After exiting fullscreen, my Projects(and thumnails in the browser) no longer display in a grid but as a single row that dissapears off the right side of the scrren and cannot be scrolled.
    Additionall the thumnail size slider and other controls that should be in the bottom right have dissapeared
    Fullscreen still works fine both in projects view and browser.
    I was wondering if anyone else has experienced similar behavior or can point me in the right direction.
    Things trie so far:
    Check other libraries (all the same)
    Repair Library (no difference)
    Rebuild Library (No Difference)

    This may be a problem of an unreadable Aperture preferences file:
    Try the following:
    Remove the Aperture's user preferences from the User Library as described here:
    Aperture 3: Troubleshooting Basics
    Note:
    Your User Library is hidden by default in 10.7.5 - to open it in a Finder window use the "Go" menu from the Finder's main menu bar.
    Quit Aperture, if it is running. Log off and on again.
    Open the user library by using the Finder's "Go > Go to Folder" menu and hold down the options-key, until "Library" appears in the drop down menu. Select it.
    In the widow that will open, scroll down to "Preferences"
    From the "Preferences" folder  remove "com.apple.Aperture.plist".
    Then try to launch Aperture again.
    But deleting the "Preferences" file will cause Aperture to forget the preferences settings. Be prepared to have to reset all options you set using the Aperture Preferences panel.
    Regards
    Léonie

  • How to display multiple lines of texts in a single rows in ALV

    Hi,
    I have a unique requirement in which i have to display multiple lines if texts for a single rows in ALV Grid. Right now in my output it is coming in single line which is not visible fully because that text is more than 255 character. So i want to display the test by splitting into multiple lines and show it on output. Please suggest some solution for this if this is possible in ALV.
    Thanks,
    Raghav

    Hi Raghavendra,
    Its not possible to display multiple line in one row of an alv, but i think you can acheive it by splitting the whole text into multiple sub-text.
    For example, if your requirement is as below:
    Field #1          Field #2
    1                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(200 characters)
    2                    yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy(220 character)
    then you can break Field#2 value into say 50 character and then populate the internal table with repetative entries of Field#1 and the finally sort it by Field#1 value... as a result of which you output will be somewhat as below:
    Field#1          Field#2
    1                   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    2                   yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
                         yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
                         yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
                         yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
                         yyyyyyyyyyyyyyyyyyyy           
    Hope it will help you in meeting your requirement.
    Regards,
    Shradha

  • Selecting multiple rows in a datagrid

    How do you make it so that you can select multiple row in a
    datagrid, and I don' t just mean like make it so you click a button
    and five different rows are suddenly highlighted. I mean like you
    manually go through and select each row that you want and it
    highlights each one as you select it.

    yourDatagrid.allowMultipleSelection=true
    should do the trick for you
    Regards
    Craig

  • Add to Selection Fails for Single Row/Column

    Hi,
    Has anyone encountered this. Making additions to selections with the Rectangular and Elliptical Marquee tools works fine. However it fails with both single row and single column marquee tools. This was doable with my previous version of Photoshop but fails on CS4.  I'm running CS4 64 bit on Windows 7.
    Thanks.

    Hi,
    Yes I did
    However this was evidentially some sort of temporary insanity on the part of PS.
    I just a short while ago shut down PS and reopened it and abracadabra the problem disappeared.
    Of course this isn't the first time that shutting down and restarting PS has "fixed" some problem I was having.

Maybe you are looking for